szes3
asked on
Deleting a Registry key via script (getting error Unable to remove registry key. Error code 8007005. )
We are having problems deleting a registry key from Windows Xp sp2 machines. We need to create a script that I can roll out to our end users that removes the following registry key.
HKEY_LOCAL_MACHINE\SOFTWAR E\Microsof t\Windows NT\CurrentVersion\Print\Pr inters\Rig htFax Fax Printer
I have created a VBS script that should remove the registry entry. But I get an error Unable to remove registry key. Error code 8007005.
Dim WshShell
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
WshShell. RegDelete"HKLM\SOFTWARE\Mi crosoft\Wi ndows NT\CurrentVersion\Print\Pr inters\Rig htFax Fax Printer\"
And have local administrator rights to the machine. It doesnt have to be a vb script. If a bat file could do the same thing that would be great also.
Thanks in advance for any insight you may provide.
HKEY_LOCAL_MACHINE\SOFTWAR
I have created a VBS script that should remove the registry entry. But I get an error Unable to remove registry key. Error code 8007005.
Dim WshShell
Set WshShell = WScript.CreateObject("WScr
WshShell. RegDelete"HKLM\SOFTWARE\Mi
And have local administrator rights to the machine. It doesnt have to be a vb script. If a bat file could do the same thing that would be great also.
Thanks in advance for any insight you may provide.
You may need to take ownership of the key first.
Uses WMI to delete the registry key HKLM\SOFTWARE\System Admin Scripting Guide.
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{ impersonat ionLevel=i mpersonate }!\\" &_
strComputer & "\root\default:StdRegProv" )
strKeyPath = "SOFTWARE\System Admin Scripting Guide"
oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
for more info and scripts see this url
http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/registry/#DelRegKey.htm
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{
strComputer & "\root\default:StdRegProv"
strKeyPath = "SOFTWARE\System Admin Scripting Guide"
oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
for more info and scripts see this url
http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/registry/#DelRegKey.htm
strKeyPath = "yourkey with the path here"
ASKER
Sundaramkumar,
So it should look like this.(see below) And save it as a .vbs and run it? If so its a no go. Never used WMI before so I may be doing something wrong.
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{ impersonat ionLevel=i mpersonate }!\\" &_
strComputer & "\root\default:StdRegProv" )
strKeyPath = "SOFTWARE\Microsoft\Window s NT\CurrentVersion\Print\Pr inters\Rig htFax Fax Printer"
oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
So it should look like this.(see below) And save it as a .vbs and run it? If so its a no go. Never used WMI before so I may be doing something wrong.
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{
strComputer & "\root\default:StdRegProv"
strKeyPath = "SOFTWARE\Microsoft\Window
oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
ASKER
Sundaramkumar,
Here is the code I am using.
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{
strComputer & "\root\default:StdRegProv"
strKeyPath = "SOFTWARE\Microsoft\Window
oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
ASKER
1stITMAN,
I have full permission on the key. All users are local administrators to the machine they use. Just to be on the safe side I went in and checked it. I have full control over that key.
When you mean take ownership to the key is there something else I have to do?
I have full permission on the key. All users are local administrators to the machine they use. Just to be on the safe side I went in and checked it. I have full control over that key.
When you mean take ownership to the key is there something else I have to do?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I've always been more familiar with batch files than any other type of scripts. I use regedit to add/remove keys on my workstations on my network.
Create a registry information file demo.reg
It is a text file, so any text editor will work. It only needs 3 lines (if you count the blank line which I have always used)
REGEDIT4
"[-HKLM\SOFTWARE\Microsoft \Windows NT\CurrentVersion\Print\Pr inters\Rig htFax Fax Printer\]"
Then the workstations need to run
regedit /s \\domaincontroller\netlogi n\demo.reg
That line can be added to their existing login script or you can create a new one.
More info for running regedit from a command line can be found here...
http://support.microsoft.com/kb/310516
Create a registry information file demo.reg
It is a text file, so any text editor will work. It only needs 3 lines (if you count the blank line which I have always used)
REGEDIT4
"[-HKLM\SOFTWARE\Microsoft
Then the workstations need to run
regedit /s \\domaincontroller\netlogi
That line can be added to their existing login script or you can create a new one.
More info for running regedit from a command line can be found here...
http://support.microsoft.com/kb/310516
search for "SetACL.exe" on sourceforge.net it allows this sort of thing from a batch file.
ASKER
This worked like a champ.
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strKeyPath = "SOFTWARE\Microsoft\Window s NT\CurrentVersion\Print\Pr inters\Rig htFax Fax Printer"
Set objReg = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv" )
DeleteSubkey strKeypath
wscript.quit
Sub DeleteSubkey(strKeyPath)
'Get a string array of subkeys
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
If IsArray(arrSubkeys) Then
'Iterate through each SubKey
For Each strSubkey In arrSubkeys
'Delete any Subkeys that are in the current subkey
DeleteSubkey strKeyPath & "\" & strSubkey
Next
End If
objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
End Sub
Thanks again for the fast repsonse and all the friendly help
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strKeyPath = "SOFTWARE\Microsoft\Window
Set objReg = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv"
DeleteSubkey strKeypath
wscript.quit
Sub DeleteSubkey(strKeyPath)
'Get a string array of subkeys
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
If IsArray(arrSubkeys) Then
'Iterate through each SubKey
For Each strSubkey In arrSubkeys
'Delete any Subkeys that are in the current subkey
DeleteSubkey strKeyPath & "\" & strSubkey
Next
End If
objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
End Sub
Thanks again for the fast repsonse and all the friendly help