Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permission Denied 800A0046 Writing to a Registry HKLM Value???

Status
Not open for further replies.

Sharpharp

IS-IT--Management
Jun 9, 2009
29
GB
Hi there,

Trying to create a registry value using vbscript on Windows 7. I am logged in as a user which is a member of the local administrators group, but when i run a vbscript to add a value under the HKLM area on the registry I get:

Permission denied, Code 800a0046 Microsoft VBScript runtime error

If i write to a HKCU value its ok and works, but not when under a HKLM, can anyone help?

I thought being a member of local admistrators group be fine to add to the registry, but clearly not for HKLM values.

Anyone able to help me?

Thanks in advance,
sharpy
 
I've run into the same problem on Windows 7. Use a registry object even for the local machine:
set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

Code:
objShell.RegWrite "HKLM\Path\To\Key\MyValue", strData, "REG_SZ"
becomes
Code:
CONST HKLM = &H80000002
objReg.SetStringValue HKLM, "Path\To\Key", "MyValue", strData

Refer to for other registry methods

-Geates
 
Thanks,

I've managed to get my original script working with evelated permissions in the script itself.

However what i was trying to achieve was to edit the registry to place a logoff script in it (the same way you would go to gpedit (locally) and add a logoff script under user configuration)

If i add a script manually using the gpedit - user configuration - add a logoff script, my logoff script works.

If i use my script, i can enter the values into the registry, but the script does not run on logout.

Am i missing something? I've added keys into the "HKLM\Software\Microsoft\Windows\CurrentVersion\Group Policy\State\SID xxxxxx x x x x\Scripts\Logoff\0\0\Script"

But still won't run.

Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top