/build/static/layout/Breadcrumb_cap_w.png

Problems with a Ristry Script

I want to delete several registry keys. I know how to delete one reg key with subkeys but I don't know how to add more reg keys with subkeys to delete.

Can you please help me?

Here is my code for one key with subkeys to delete. Works perfectly... How to add more keys in HKEY_CURRENT_USER\Software\Test, HKEY_CURRENT_USER\Software\Test1, HKEY_CURRENT_USER\Software\Test2.... to delete?

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006

Const COMPUTER = "."

Sub DeleteKey(Hive, KeyPath)
Dim ValueArray, Value

' List subkeys
objReg.EnumKey Hive, KeyPath, ValueArray

If Not IsNull(ValueArray) Then
For Each Value In ValueArray
' Starts recursion
DeleteKey Hive, KeyPath + "\" + Value
Next
End If
' Deletes the key
objReg.DeleteKey Hive, KeyPath + "\" + Value
End Sub

Dim KeyPath
Dim objReg

Set objReg = _
GetObject("winmgmts:\\" &_
COMPUTER & "\root\default:StdRegProv")

KeyPath = "Software\Test"

DeleteKey HKEY_CURRENT_USER, KeyPath

0 Comments   [ + ] Show comments

Answers (4)

Posted by: Jsaylor 14 years ago
Second Degree Blue Belt
0
Just call the sub function with different arguments again.

You have the sub being called with:

DeleteKey HKEY_CURRENT_USER, KeyPath

Keypath being assigned as "Software\Test." To run this multiple times, just call the sub again with the keypath argument replaced. For simplicity's sake, you could do this to delete the key HKCU\Software\test2:

DeleteKey HKEY_CURRENT_USER, "Software\Test2"

You can call the sub as many times as you like in this fashion. There are more powerful ways to automate this to use lists, but I believe just calling the sub for each key you want to delete in this manner should get you where you need to be.
Posted by: McRip 14 years ago
Orange Senior Belt
0
I was too late posting my new code. You have been a bit faster...

Here is my new code and it works.

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006

Const COMPUTER = "."

Sub DeleteKey(Hive, KeyPath)
Dim ValueArray, Value

' List subkeys
objReg.EnumKey Hive, KeyPath, ValueArray

If Not IsNull(ValueArray) Then
For Each Value In ValueArray
' Starts recursion
DeleteKey Hive, KeyPath + "\" + Value
Next
End If
' Deletes the key
objReg.DeleteKey Hive, KeyPath + "\" + Value
End Sub

Dim objReg

Set objReg = _
GetObject("winmgmts:\\" &_
COMPUTER & "\root\default:StdRegProv")

DeleteKey HKEY_CURRENT_USER, "Software\Test"
DeleteKey HKEY_CURRENT_USER, "Software\Test1"
DeleteKey HKEY_CURRENT_USER, "Software\Test2"
DeleteKey HKEY_CURRENT_USER, "Software\Test3"
DeleteKey HKEY_CURRENT_USER, "Software\Test4"


Nevertheless, thanks for help


EDIT: The reason for it, I need this in order to get a clean state of the machines on Windows 7. Windows Installer remains several keys after uninstalling. It's all marked to delete the keys on uninstall in the tables but anyhow windows installer leaves them on the machine on Windos 7. And I guess the same happens on VISTA machines...
Posted by: anonymous_9363 14 years ago
Red Belt
0
...or go completely mad and use the RemoveRegistry table.

BTW, if you want to persist with registry-handling via script, get hold of the cRegistry class from JSWare (http://www.jsware.net) IIRC, it's part of the class pack there. I use an edited version of this class for any script which requires access to the registry and it has proved its worth over and over, not the least of which is the time-saver of not having to create the same functions ad infinitum. There's an INI handling class there, too. The one feature common to both is a means to enumerate keys (or sections in the INI class), values and values with their data. That alone makes it head and shoulders above the brain-dead registry scripts you'll find knocking around.

Don't be put off by the scary word 'class'. Using it is simple and usage is explained in the file itself.
Posted by: McRip 14 years ago
Orange Senior Belt
0
ORIGINAL: VBScab

...or go completely mad and use the RemoveRegistry table.



I did use the RemoveRegistry table but it did not work correctly on Windows 7 machines, that's the point. I was testing around with my VBScript and it works perfectly. Now the Windows 7 machine is in a clean state after uninstalling...

But I will adopt your proposal for (http://www.jsware.net). I'm gonna study this one for a while and will then make my choice.

Thank you
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
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