WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

User Profiles

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Load a User Profile into the Registry

 Keywords:  

Answer:

This article describes how to use the RegLoadHive registry function to load a user profile into the registry and, subsequently, how to use RegUnLoadHive to unload the user profile.

MORE INFORMATION
In part, the registry consists of files that store information about a user profile. When this file is loaded, it maps to the HKEY_USERS or HKEY_LOCAL_MACHINE key, whichever is specified in the call to RegLoadHive.

To retrieve user profile-specific information, you can load the NtUser.dat file that is located in the profile path of the user profile that you want to load. It may be necessary to load a hive (user profile) when you try to provide profile-specific data.

The following steps illustrate how to load NtUser.dat and unload it when finished. These methods are not a threat to security because they only succeed if the calling process and the impersonated user have sufficient privileges.

Example

Using registry functions incorrectly can cause major problems. Use Registry Functions at your own risk. Note that you should back up the registry before you edit it. If you are running Windows NT or Windows 2000, you should also update your Emergency Repair Disk (ERD).

strKeyName="Keyloaded"     
;Path to file on Windows NT: C:\WinNT\Profiles\{Profile Name}\NtUser.Dat
;Path to file on Windows 2000: C:\Documents and Settings\{Profile Name}\NtUser.Dat
datfile = "C:\Documents and Settings\{Profile Name}\NtUser.Dat"
if fileexist(datfile)
	ErrorMode(@off) 
	Retval = RegLoadHive(@REGUSERS, strKeyName, datfile)
	ErrorMode(@cancel) 
	If Retval == 0 
	   Message( "RegLoadHive failed: " , Retval)
		exit
	endif
	Pause( "RegLoadHive successful: " , "From the Windows Start menu, click Run, type regedit(on Windows NT) or regedt32(on Windows 2000), and then click OK. Locate the HKEY_USERS subtree. Notice that this subtree includes the new key,KeyLoaded.'")          

	ErrorMode(@off) 
	Retval = RegUnLoadHive(@REGUSERS, strKeyName)
	ErrorMode(@cancel) 
	If Retval == 0 
	   Message( "RegUnLoadHive failed: " , Retval)
		exit
	endif
	Message("Finished","Loading, then unloading user profile")
else
	Message("Cannot locate dat file","Make sure path specified is correct")
endif

Article ID:   W14856
File Created: 2003:05:28:12:45:20
Last Updated: 2003:05:28:12:45:20