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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DeleteKey in registry

Status
Not open for further replies.

Stephon98caffe

Programmer
Feb 18, 2005
25
US
The registry is not delete once I go into regedit. Does the code I have looking right

On Error Resume Next
Const HKU = &H80000003

strComputer = "."
Set StdOut = CreateObject("WScript.StdOut")
sMethod = "DeleteKey"


Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

Set oReg2=GetObject("winmgmts:{impersonationLevel=impersonate}!//" &_
strComputer & "/root/default:StdRegProv")

Set oReg3=GetObject("winmgmts:{impersonationLevel=impersonate}!//" &_
strComputer & "/root/default:StdRegProv")

Set oReg4=GetObject("winmgmts:{impersonationLevel=impersonate}!//" &_
strComputer & "/root/default:StdRegProv")

Set oReg5=GetObject("winmgmts:{impersonationLevel=impersonate}!//" &_
strComputer & "/root/default:StdRegProv")


strKeyPath = ""
oReg.EnumKey HKU, strKeyPath, arrSubKeys

set oMethod = oReg.Methods_(sMethod)
set oInParam = oMethod.inParameters.SpawnInstance_()

strdeleteKeyPath = ""

For Each subkey In arrSubKeys
' .DEFAULT, etc.
' Check for the contents of HKEY_USERS->Software


strKeyPath2 = subkey & "\Software"




oReg2.EnumKey HKU, strKeyPath2, arrSubKeys2
For Each subkey2 In arrSubKeys2
If subkey2 = "CENS Client" Then
' Nelda said that if the "CENS Client" hive exists, then assume the Settings sub-hive exists
strKeyPath3 = strKeyPath2 & "\CENS Client\Settings"

strdeleteKeyPath = "\CENS Client\Settings"
Wscript.Echo strKeyPath3

' 'Delete the ...\CENS Client\Settings hive
Return = objReg.DeleteKey(HKU,strKeyPath3)
Wscript.Echo Return
Else
End If

Next

Next
 
To be sure, comment out the On Error instruction.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
no error occurs it just doesn't delete registry folder. I think it is a permission issue b/c folder is only read access for
 
For winnt up, it is necessary to first delete the subkeys and subkeys' content before deleting is key itself.
 
yeap, i tried that and ended up writing a recursive sub to delete registry keys using WMI. cant find the source code though :-(
 
did you get anywhere with my previous suggestions in your previous thread on the same issue???
 
use the reg delete /f option under cmd in the script with a variable, it can delete keys and subkeys in one time forced. U can use the hide window wait for return option.

good luck, worked for me!

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top