/build/static/layout/Breadcrumb_cap_w.png

VBScript to Update Current User Registry

Hello, 

Below function can be used to update user registry using HKU Registry hive without using ActiveSetup:


'User registry update function variables
Dim strRegPathSuffix,strRegValueName,strRegValuDec,strISString,strISDword


'Define Registry Hive Constants
Const HKU  = &H80000003

'Function to update Registry for Computer users
Function UpdateUserReg(strRegPathSuffix,strRegValueName,strRegValuDec,strISString, strISDword)
Dim oReg,arrSubKeys,subkey,strKeyPath
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
strKeyPath = ""
oReg.EnumKey  HKU, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
    'wscript.echo subkey
'Only set regsirty for existing users, hency excluding foloowing: .DEFAULT or S-1-5-18 or S-1-5-19 or S-1-5-20 or _Classes
If NOT ((InStr(1,subkey,".DEFAULT",1) > 0) OR (InStr(1,subkey,"S-1-5-18",1) > 0) OR (InStr(1,subkey,"S-1-5-19",1) > 0) OR (InStr(1,subkey,"S-1-5-20",1) > 0) OR (InStr(1,subkey,"_Classes",1) > 0)) Then
'Create desired registry key/value
strKeyPath = subkey & "\" & strRegPathSuffix
'wscript.echo strKeyPath
oReg.CreateKey  HKU, strKeyPath
sWriteLog "Updating User Regsitry: " & "HKEY_Current_USERS\" & "\" & strRegPathSuffix & "\" & strRegValueName & "=" & strRegValuDec
' oReg.SetDWORDValue HKEY_USERS, strKeyPath, strRegValueName, strRegValuDec
If (strISString = 1) Then errorCode = oReg.SetStringValue(HKU, strKeyPath, strRegValueName, strRegValuDec)
If (strISDword = 1) Then errorCode = oReg.SetDWORDValue(HKU, strKeyPath, strRegValueName, strRegValuDec)
sWriteLog "Return Code: " & errorCode
End If
Next
End Function


'Calling Function
'Variable Definition for Function
'Call UpdateUserReg(strRegPathSuffix,strRegValueName,strRegValuDec,strISString, strISDword)

'If it has to be String strISString should be 1 else 0,
'Call UpdateUserReg("Software\Test\TestApplication\Settings","TestDWORD","122",0, 1)

'Similarly for DWORD strISDword should be 1 else 0
'Call UpdateUserReg("Software\Test\TestApplication\Settings","TestSTRING","TestValue",0, 1)


'Hope it is useful
'Best Regards, 
'The_D

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