Skip navigation

How can I update a registry value for all users on a machine?

A. To update all users at once, you need to update values via the HKEY_USERS key. The following code, which you can download here enumerates through all the users under HKEY_USERS and sets part of a binary value (in this example, the setting to control the "perform no action when a laptop lid is shut" under Power Settings). You can change the code in the example to perform whatever actions you want.

const HKEY_USERS = &H80000003
Dim binValue()
strComputer = "."

Set objReg=GetObject("winmgmts:\{impersonationLevel=impersonate\}!\\" _ 
   & strComputer & "\root\default:StdRegProv")

strKeyPath = ""
objReg.EnumKey HKEY_USERS, strKeyPath, arrSubKeys

strKeyPath = "\Control Panel\PowerCfg\GlobalPowerPolicy"
strKeyPathUser = "\Software\Microsoft\Windows\CurrentVersion\Explorer"

For Each subkey In arrSubKeys
    if objReg.GetBinaryValue(HKEY_USERS, subkey & strKeyPath, "Policies", binValue) = 0 then
       objReg.GetStringValue HKEY_USERS, subkey & strKeyPathUser, "Logon User Name", userName
       Wscript.Echo "Updating SID - " & subkey & ", Username - " & userName
       objReg.SetBinaryValue HKEY_USERS, subkey & strKeyPath, "Policies", binValue
    end if
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.