Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've done this many times. The idea is to update the currently logged on user's HKCU (that's easy enough). Then you must enumerate every profile on the system and find their ntuser.dat file (that's easy enough too).</p> <p>With the ntuser.dat file found, you load it into a temporary key in the HKLM hive (I usually use 'HKLM\TempHive'. Then edit away.</p> <p>If there is more than 1 user logged on, their profile will be loaded under HKEY_USERS, by their SID. Simply update that location.</p> <p>To modify the setting for any new users, simply modify the appropriate key under HKEY_USERS.DEFAULT, OR use the Delphi code below which will do this by loading the Default Users's HKCU registry hive (stored in ntuser.dat).</p> <p><strong>UPDATE</strong>: I found my Delphi code that demonstrates how to update the HKCU hives of users that are not logged onto the system.</p> <p>This requires Russell Libby's 'Privilege' component, <a href="http://home.roadrunner.com/~rllibby/downloads/privilege.zip" rel="noreferrer">which is available here</a>.</p> <pre><code>//NOTE: sPathToUserHive is the full path to the users "ntuser.dat" file. // procedure LoadUserHive(sPathToUserHive: string); var MyReg: TRegistry; UserPriv: TUserPrivileges; begin UserPriv := TUserPrivileges.Create; try with UserPriv do begin if HoldsPrivilege(SE_BACKUP_NAME) and HoldsPrivilege(SE_RESTORE_NAME) then begin PrivilegeByName(SE_BACKUP_NAME).Enabled := True; PrivilegeByName(SE_RESTORE_NAME).Enabled := True; MyReg := TRegistry.Create; try MyReg.RootKey := HKEY_LOCAL_MACHINE; MyReg.UnLoadKey('TEMP_HIVE'); //unload hive to ensure one is not already loaded if MyReg.LoadKey('TEMP_HIVE', sPathToUserHive) then begin //ShowMessage( 'Loaded' ); MyReg.OpenKey('TEMP_HIVE', False); if MyReg.OpenKey('TEMP_HIVE\Environment', True) then begin // --- Make changes *here* --- // MyReg.WriteString('KEY_TO_WRITE', 'VALUE_TO_WRITE'); // // end; //Alright, close it up MyReg.CloseKey; MyReg.UnLoadKey('TEMP_HIVE'); //let's unload the hive since we are done with it end else begin WriteLn('Error Loading: ' + sPathToUserHive); end; finally FreeAndNil(MyReg); end; end; WriteLn('Required privilege not held'); end; finally FreeAndNil(UserPriv); end; end; </code></pre> <p>I also wrote a VBScript a while ago that accomplishes this task. I used it for modifying some Internet Explorer settings, but you can customize it to your needs. It also demonstrates the general process:</p> <pre><code>Option Explicit Dim fso Dim WshShell Dim objShell Dim RegRoot Dim strRegPathParent01 Dim strRegPathParent02 Set fso = CreateObject("Scripting.FileSystemObject") Set WshShell = CreateObject("WScript.shell") '============================================== ' Change variables here '============================================== ' 'This is where our HKCU is temporarily loaded, and where we need to write to it RegRoot = "HKLM\TEMPHIVE" ' strRegPathParent01 = "Software\Microsoft\Windows\CurrentVersion\Internet Settings" strRegPathParent02 = "Software\Microsoft\Internet Explorer\Main" ' '====================================================================== Call ChangeRegKeys() 'Sets registry keys per user Sub ChangeRegKeys 'Option Explicit On Error Resume Next Const USERPROFILE = 40 Const APPDATA = 26 Dim iResult Dim iResult1 Dim iResult2 Dim objShell Dim strUserProfile Dim objUserProfile Dim strAppDataFolder Dim strAppData Dim objDocsAndSettings Dim objUser Set objShell = CreateObject("Shell.Application") Dim sCurrentUser sCurrentUser = WshShell.ExpandEnvironmentStrings("%USERNAME%") strUserProfile = objShell.Namespace(USERPROFILE).self.path Set objUserProfile = fso.GetFolder(strUserProfile) Set objDocsAndSettings = fso.GetFolder(objUserProfile.ParentFolder) 'Update settings for the user running the script '(0 = default, 1 = disable password cache) WshShell.RegWrite "HKCU\" &amp; strRegPathParent01 &amp; "\DisablePasswordCaching", "00000001", "REG_DWORD" WshShell.RegWrite "HKCU\" &amp; strRegPathParent02 &amp; "\FormSuggest PW Ask", "no", "REG_SZ" strAppDataFolder = objShell.Namespace(APPDATA).self.path strAppData = fso.GetFolder(strAppDataFolder).Name ' Enumerate subfolders of documents and settings folder For Each objUser In objDocsAndSettings.SubFolders ' Check if application data folder exists in user subfolder If fso.FolderExists(objUser.Path &amp; "\" &amp; strAppData) Then 'WScript.Echo "AppData found for user " &amp; objUser.Name If ((objUser.Name &lt;&gt; "All Users") and _ (objUser.Name &lt;&gt; sCurrentUser) and _ (objUser.Name &lt;&gt; "LocalService") and _ (objUser.Name &lt;&gt; "NetworkService")) then 'Load user's HKCU into temp area under HKLM iResult1 = WshShell.Run("reg.exe load " &amp; RegRoot &amp; " " &amp; chr(34) &amp; objDocsAndSettings &amp; "\" &amp; objUser.Name &amp; "\NTUSER.DAT" &amp; chr(34), 0, True) If iResult1 &lt;&gt; 0 Then WScript.Echo("*** An error occurred while loading HKCU: " &amp; objUser.Name) Else WScript.Echo("HKCU loaded: " &amp; objUser.Name) End If WshShell.RegWrite RegRoot &amp; "\" &amp; strRegPathParent01 &amp; "\DisablePasswordCaching", "00000001", "REG_DWORD" WshShell.RegWrite RegRoot &amp; "\" &amp; strRegPathParent02 &amp; "\FormSuggest PW Ask", "no", "REG_SZ" iResult2 = WshShell.Run("reg.exe unload " &amp; RegRoot,0, True) 'Unload HKCU from HKLM If iResult2 &lt;&gt; 0 Then WScript.Echo("*** An error occurred while unloading HKCU: " &amp; objUser.Name &amp; vbcrlf) Else WScript.Echo(" unloaded: " &amp; objUser.Name &amp; vbcrlf) End If End If Else 'WScript.Echo "No AppData found for user " &amp; objUser.Name End If Next End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload