VBScript not removing the reg. key
Hi,
I am using VB script to remove reg. key. In my vb, I am running .reg file to delete it, I have also tried using the following code to remove but not luck:
const HKEY_CURRENT_USER = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\[ProductName]"
oReg.DeleteKey HKEY_CURRENT_USER, strKeyPath
Can someone think or see something here that I might be missing?
Thanks
I am using VB script to remove reg. key. In my vb, I am running .reg file to delete it, I have also tried using the following code to remove but not luck:
const HKEY_CURRENT_USER = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\[ProductName]"
oReg.DeleteKey HKEY_CURRENT_USER, strKeyPath
Can someone think or see something here that I might be missing?
Thanks
0 Comments
[ + ] Show comments
Answers (4)
Answer Summary:
Please log in to answer
Posted by:
shigbee
12 years ago
I use REG DELETE "HKEY_LOCAL_MACHINE... in a batch file to remove registry keys and i also use this vbs as well.
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Set wmiLocator = CreateObject("WbemScripting.SWbemLocator")
Set wshNetwork = CreateObject("WScript.Network")
Set wmiNameSpace = wmiLocator.ConnectServer(wshNetwork.ComputerName, "root\default")
Set objRegistry = wmiNameSpace.Get("StdRegProv")
' Deletes Key with alle subkeys
sPath1 = "Software\..."
sPath2 = "Software\..."
sPath3 = "SOFTWARE\....\"
lRC = DeleteRegEntry(HKEY_CURRENT_USER, sPath1)
lRC = DeleteRegEntry(HKEY_LOCAL_MACHINE, sPath2)
lRC = DeleteRegEntry(HKEY_LOCAL_MACHINE, sPath3)
Function DeleteRegEntry(sHive, sEnumPath)
lRC = objRegistry.DeleteKey(sHive, sEnumPath)
If (lRC <> 0) Then
On Error Resume Next
lRC = objRegistry.EnumKey(HKEY_CURRENT_USER, sEnumPath, sNames)
For Each sKeyName In sNames
If Err.Number <> 0 Then Exit For
lRC = DeleteRegEntry(sHive, sEnumPath & "\" & sKeyName)
Next
On Error Goto 0
lRC = objRegistry.DeleteKey(sHive, sEnumPath)
End If
End Function
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Set wmiLocator = CreateObject("WbemScripting.SWbemLocator")
Set wshNetwork = CreateObject("WScript.Network")
Set wmiNameSpace = wmiLocator.ConnectServer(wshNetwork.ComputerName, "root\default")
Set objRegistry = wmiNameSpace.Get("StdRegProv")
' Deletes Key with alle subkeys
sPath1 = "Software\..."
sPath2 = "Software\..."
sPath3 = "SOFTWARE\....\"
lRC = DeleteRegEntry(HKEY_CURRENT_USER, sPath1)
lRC = DeleteRegEntry(HKEY_LOCAL_MACHINE, sPath2)
lRC = DeleteRegEntry(HKEY_LOCAL_MACHINE, sPath3)
Function DeleteRegEntry(sHive, sEnumPath)
lRC = objRegistry.DeleteKey(sHive, sEnumPath)
If (lRC <> 0) Then
On Error Resume Next
lRC = objRegistry.EnumKey(HKEY_CURRENT_USER, sEnumPath, sNames)
For Each sKeyName In sNames
If Err.Number <> 0 Then Exit For
lRC = DeleteRegEntry(sHive, sEnumPath & "\" & sKeyName)
Next
On Error Goto 0
lRC = objRegistry.DeleteKey(sHive, sEnumPath)
End If
End Function
Posted by:
rock_star
12 years ago
I hope you are trying to delete it from HKLM hive.. as mentioned in script const HKEY_CURRENT_USER = &H80000002
Also , Are there any other registry entries inside this hive. SOFTWARE\[ProductName]
Then you have to delete them .
=================================================================
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strKeyPath = "Installer\Products"
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
DeleteSubkeys HKEY_LOCAL_MACHINE, strKeypath
Sub DeleteSubkeys(HKEY_CLASSES_ROOT, strKeyPath)
objRegistry.EnumKey HKEY_CLASSES_ROOT, strKeyPath, arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys HKEY_CLASSES_ROOT, strKeyPath & "\" & strSubkey
Next
End If
objRegistry.DeleteKey HKEY_CLASSES_ROOT, strKeyPath
End Sub
===============================================================
Also , Are there any other registry entries inside this hive. SOFTWARE\[ProductName]
Then you have to delete them .
=================================================================
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strKeyPath = "Installer\Products"
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
DeleteSubkeys HKEY_LOCAL_MACHINE, strKeypath
Sub DeleteSubkeys(HKEY_CLASSES_ROOT, strKeyPath)
objRegistry.EnumKey HKEY_CLASSES_ROOT, strKeyPath, arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys HKEY_CLASSES_ROOT, strKeyPath & "\" & strSubkey
Next
End If
objRegistry.DeleteKey HKEY_CLASSES_ROOT, strKeyPath
End Sub
===============================================================
Posted by:
dchristian
12 years ago
Posted by:
786_ak
12 years ago