/build/static/layout/Breadcrumb_cap_w.png

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

0 Comments   [ + ] Show comments

Answers (4)

Answer Summary:
Posted by: shigbee 12 years ago
2nd Degree Black Belt
1
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
Posted by: rock_star 12 years ago
4th Degree Black Belt
1
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

===============================================================
Posted by: dchristian 12 years ago
Red Belt
0
What tool are you using to deploy the script? If your deleting from HKCU is the script running as the user?
Posted by: 786_ak 12 years ago
Third Degree Green Belt
0
Folks, thanks for all of your feedback. This issue has been resolved now. I caught my mistake, and now the script is working flawlessly. Once again thanks for all the input.

Thanks
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ