/build/static/layout/Breadcrumb_cap_w.png

Vbscript to write HKCU registries to logged on user using system account

Below script will help to write HKCU registries to currently logged in user using any other account e.g. system account. This will also help when you don't want user to do a logoff login for Active Setup to perform it's job.

'----------------------------------------------------------------------------------------------------------------
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_USERS = &H80000003
strComputer = "."

Set WShell = CreateObject( "WScript.Shell")
Set FSO = CreateObject( "Scripting.FileSystemObject")
Set WNetwork = CreateObject("WScript.Network")

'----------------------------------------------------------------------------------------------------------------


Set objRegistry=GetObject( "winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
Set objReg = GetObject( "winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

'----------------------------------------------------------------------------------------------------------------

For Each objSubkey In arrSubkeys
strValueName = "Volatile Environment"
strSubPath = strKeyPath & "\" & objSubkey
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue
Next


strUserName = WNetwork.username

If UCase(strUserName) = "SYSTEM" Then
string1 = "S-1-5-21"
string2 = "Classes"
objReg.EnumKey HKEY_USERS, "", arrsubkeys
For Each Subkey In arrSubKeys
If InStr(1,Subkey, string1,1)And (InStr(1,Subkey, string2,1) = "0") Then
Key = "HKEY_USERS\" & Subkey & "\SOFTWARE\Test Key\Something"
msgbox Key
Wshell.RegWrite Key, "1", "REG_DWORD"
End If
Next
Else

End If

Comments

This post is locked

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ