0
votes

I am trying to delete a registry key. Here is my code:

Option Explicit
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )  
Dim strDelete
strDelete = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\test\")
WScript.echo(strDelete)
objShell.RegDelete "HKEY_LOCAL_MACHINE\SOFTWARE\test\"
WScript.Quit

When I run this, I get this output:

Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

test
N:\RogueDevelopment\test.vbs(23, 1) WshShell.RegDelete: Invalid root in registry key "HKEY_LOCAL_MACHINE\SOFTWARE\test\".

My registry key is located at "HKEY_LOCAL_MACHINE\SOFTWARE\test\" and it has a default value of "test". The value in the key is being read correctly, but the key cannot be deleted. I am running this script on Windows 7. Why is this happening?

1
UAC prevents you from deleting keys in HKLM. Use HKCU instead. - Hans Passant
Not booted into Windows partition right now, but I suspect that you shouldn't use the trailing backslash after the last "t" in test "test\". That, and it's probably an admin permissioning problem as Neil suggests below. - selbie

1 Answers

0
votes

You don't have permission to open HKEY_LOCAL_MACHINE\SOFTWARE\test\ for delete access. If you really need to modify keys under HKLM, you will need to elevate your process.