r/vbscript • u/ExBx • Feb 26 '21
Creating registry key using the HKEY_USERS path.
This script basically prompts the admin for the ID number that is found in Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList for the "current user" on that machine I'm targeting. Based on the variables I created by concatenating the strUID and the registry key path it equals S-1-2-3-4-234234234\SOFTWARE\Policies\Google
Therefor the command objRegistry.CreateKey HKEY_USERS, strKeyGoogle should be creating a key "Google" located here Computer\HKEY_USERS\S-1-2-3-4-234234234\SOFTWARE\Policies\Google
The script runs but the key isn't being created. (And I'm executing the .vbs from an Administrator command window)
Has anyone attempted such a thing? I would assume it's possible but I'm not having much luck. Thank you.
Do While X = 0
strUID = InputBox _
("Please enter the user registry UID:")
If strUID = "" Then
Wscript.Echo "You must enter a UID."
Else
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
'Combine UID and the new key path
strKeyGoogle = strUID & "\SOFTWARE\Policies\Google"
'Confirm the variables have been set
Wscript.Echo strUID
Wscript.Echo strKeyGoogle
'Add new registry to specific user
objRegistry.CreateKey HKEY_USERS, strKeyGoogle
End If
Exit Do
Loop
1
u/ExBx Feb 26 '21
I wasn't able to find any definitive answers on the forums to make it work so I just decided to pipe the vars out to CMD and run it that way. Simple, efficient, and it works. +And it anyone wants to know what this does, it enables an "Always Allow" checkbox on Chrome "Do you want to allow this application to run?" pop-ups + also permits click to call tel:\\ hyperlinks to open the default softphone protocol handler without asking the user each time.
1
u/jcunews1 Feb 27 '21
By Windows, user registry hives are only loaded when the user is atually being used for login or execute a program.
1
u/Mordac85 Mar 18 '21
Have you tried logging in as that user to see if the key is present after the hive is loaded? I know I went down this rabbit hole once before and dropped it, but I can't remember why but I know this route can give some odd behavior.