Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


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\\NtUser.Dat
;Path to file on Windows 2000: C:\Documents and Settings\\NtUser.Dat
datfile = "C:\Documents and Settings\\NtUser.Dat"
if fileexist(datfile) 
	Retval = RegLoadHive(@REGUSERS, strKeyName, datfile)
	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.'")          
	
	 Retval = RegUnLoadKey(HKEY_USERS, strKeyName)
	 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