It is important to understand that HKCU is the user hive for the current user and is different for each user. So you need to decide if you want the setting set for a specific user or for all users. The other thing to understand is that user hives are typically not mounted and not accessible unless the user is logged in. You can access these hives using the system account but you need to mount them first.
Here is a VBS function I use from within Altiris scripts when I need to modify user hives. You won't be able to use this as is because it references other functions from our custom library but you should get the idea of how it works.
'Set USER level registry settings
Call WriteUserHiveSetting("\Software\ACME\SampleApp\Preferences", "ShowWelcomeScreen", 0, "REG_DWORD", "Disable Welcome Screen for SampleApp", "", "C:\temp\ACMESample.log")
Sub WriteUserHiveSetting(strHivePath, strRegValue, strRegData, strRegType, strRegDescription, strTrackingKey, strLogFile)
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Name: WriteUserHiveSetting(), v1.1.4894
' Description: Modifies a user registry hive setting in all user hives.
' Arguments:
' - strHivePath - Path within the user hive to modify.
' - strRegValue - item in the registry key
' - strRegData - Data to put in the registry value
' - strRegType - Registry value type such as "REG_DWORD"
' - strRegDescription - Description of the key, used only for logging
' - strTrackingKey - registry value used to write tracking information, pass "" if tracking key not used
' - strLogFile - Name of log file to append or create
' Dependencies: GetEnvironVar(), GetRegKeyExists(), GetEnumRegKeys(), WriteRegValue(), WriteLogFile()
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Declare variables
Dim objFso ' used for working with file system object
Dim colKeys, strKey ' list of mounted user profiles
Dim objWshShell ' used for working with shell object
Dim objProfilesDir, objUserDir, strUserHive 'used for working with profile directories
Dim intHiveLoad 'return code from mounting user registry hives
' Create objects
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objWshShell = CreateObject("WScript.Shell")
' Log header for this sub - all other entries indented
Call WriteLogFile(strLogFile, "*** Adjusting User Hives. Purpose: " & strRegDescription & " ***")
'### Update MOUNTED user hives ###
'format the input strings
If Left(strHivePath,1) <> "\" Then strHivePath = "\" & strHivePath
'Determine list of local Profiles
colKeys = GetEnumRegKeys("HKLM", "Software\Microsoft\Windows NT\CurrentVersion\ProfileList")
For Each strKey in colKeys
'Check to see if the SID is a valid, mounted hive
If len(strKey) > 10 And Instr(strKey, "_Classes") = 0 And GetRegKeyExists("HKEY_USERS\" & strKey) Then
Call WriteLogFile(strLogFile, " ## Adding '" & strRegDescription & "' to MOUNTED User hive : " & strKey)
Call WriteRegValue("HKEY_USERS", strKey & strHivePath, strRegValue, strRegData, strRegType, strTrackingKey, strLogFile)
End If
Next
'### Update UNMOUNTED user hives ###
Set objProfilesDir = objFso.GetFolder(GetEnvironVar("[PROFILESDIRECTORY]"))
For Each objUserDir in objProfilesDir.SubFolders
strUserHive = objUserDir.path & "\ntuser.dat"
If objFso.FileExists(strUserHive) And objUserDir.Name <> "All Users" And objUserDir.Name <> "LocalService" And objUserDir.Name <> "NetworkService" Then
Call WriteLogFile(strLogFile, " ## Preparing to mount user hive : " & objUserDir.Name)
intHiveLoad = objWshShell.Run("reg load HKU\TEMP " & Chr(34) & strUserHive & Chr(34),0,True)
'Check to see if there was a problem loading the hive
If intHiveLoad = 1 Then
Call WriteLogFile(strLogFile, " Unable to mount User Hive into registry for " & objUserDir.name & ". May already be mounted")
Else
Call WriteLogFile(strLogFile, " Adding '" & strRegDescription & "' to " & objUserDir.name)
Call WriteRegValue("HKEY_USERS", "TEMP" & strHivePath, strRegValue, strRegData, strRegType, strTrackingKey, strLogFile)
'Unload the user registry hive
objWshShell.Run "reg unload HKU\TEMP", 0, True
End If
WriteLogFile strLogFile, " Completed processing user hive : " & objUserDir.Name
End If
Next
End Sub