/build/static/layout/Breadcrumb_cap_w.png

VBScript to delete reg key that has subkeys.

Hi,

I have HKLM\Software\Humm. Humm contains may other subkeys.

Is there a script that will delete Humm and all it's subkeys?

Thanks,

Mike.

0 Comments   [ + ] Show comments

Answers (14)

Posted by: Rave 17 years ago
Senior Yellow Belt
4
Hello Mike,

i think the following script should work.
Copy & Past it in Primalscript, You have to change the strkeypath with the key(s) you want to delete, you can also use this to delete only one regkey.

'*******Begin script*********
On Error Resume Next

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
strKeyPath = "Software\Test"

Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

DeleteSubkeys HKEY_LOCAL_MACHINE, strKeypath

Sub DeleteSubkeys(HKEY_LOCAL_MACHINE, strKeyPath)
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys HKEY_LOCAL_MACHINE, strKeyPath & "\" & strSubkey
Next
End If
objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
End Sub
'*******End Script*******

Regards,
Rave
Posted by: Meic 17 years ago
Second Degree Blue Belt
0
Hi Rave,

Thanks very much - worked a treat!

Cheers, Mike.
Posted by: veday001 16 years ago
Senior Yellow Belt
0

For Each strSubkey In arrSubkeys


Thanks Mate... Script did a job for me [;)]
Posted by: eddysj 14 years ago
Yellow Belt
0
'*******Begin script*********
On Error Resume Next

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
strKeyPath = "Software\Test"

Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

DeleteSubkeys HKEY_LOCAL_MACHINE, strKeypath

Sub DeleteSubkeys(HKEY_LOCAL_MACHINE, strKeyPath)
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys HKEY_LOCAL_MACHINE, strKeyPath & "\" & strSubkey
Next
End If
objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
End Sub
'*******End Script*******


I need change this script to delete key and subkey from all users (HKCU\Software\Test - Main Registry) in computer.
How can I adapt this script to do it?

Regards
Posted by: anonymous_9363 14 years ago
Red Belt
0
The script isn't particularly well-coded, having HKEY_LOCAL_MACHINE hard-wired into the function. I recommend you download the class pack from JSWare.net which includes a registry class. This has a number of useful functions which you'll find easy to use. However, I appreciate that most people ignore my advice, so: Option Explicit

Dim intHive
Dim strComputer
Dim strKeyPath

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

On Error Resume Next

strComputer = "."
'intHive = HKEY_LOCAL_MACHINE
intHive = HKEY_CURRENT_USER
strKeyPath = "Software\Test"

Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

DeleteSubkeys intHive, strKeypath

Set objRegistry = Nothing

Sub DeleteSubkeys(ByVal intRegistryHive, ByVal strRegistryKey)
Dim arrSubkeys

objRegistry.EnumKey intRegistryHive, strRegistryKey, arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys intRegistryHive, strRegistryKey & "\" & strSubkey
Next
End If

objRegistry.DeleteKey intRegistryHive, strRegistryKey
End Sub
Posted by: eddysj 14 years ago
Yellow Belt
0
ORIGINAL: VBScab

The script isn't particularly well-coded, having HKEY_LOCAL_MACHINE hard-wired into the function. I recommend you download the class pack from JSWare.net which includes a registry class. This has a number of useful functions which you'll find easy to use. However, I appreciate that most people ignore my advice, so: Option Explicit

Dim intHive
Dim strComputer
Dim strKeyPath

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

On Error Resume Next

strComputer = "."
'intHive = HKEY_LOCAL_MACHINE
intHive = HKEY_CURRENT_USER
strKeyPath = "Software\Test"

Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

DeleteSubkeys intHive, strKeypath

Set objRegistry = Nothing

Sub DeleteSubkeys(ByVal intRegistryHive, ByVal strRegistryKey)
Dim arrSubkeys

objRegistry.EnumKey intRegistryHive, strRegistryKey, arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys intRegistryHive, strRegistryKey & "\" & strSubkey
Next
End If

objRegistry.DeleteKey intRegistryHive, strRegistryKey
End Sub



No, this script delete key just to user logged. I need delete the key to others users too. For exemple, I'm logged with User01 and when I execute the script, I want delete the key in Current User to User01, User02, User03.

Regards
Posted by: anonymous_9363 14 years ago
Red Belt
0
Then you have to get into the mire of using REG.EXE to load the user's hive [shudder]....

Why not run the script as an Active Setup job?
Posted by: naveen.packager 13 years ago
Green Belt
0
Hi All,

I have a similar requirement as edd has.

I have captured a setup to an msi, this application has a file association which is present already in OS. So when i unistall the app th file association will dissappear. So i have added that association in HKCU\Software\Classes. But this will restore the association only for administrator(from where the application is uninstalled).

So I wanted to use a vbscript while uninstalling the app which will search all users HKCU\Software\Classes and will delete it for every user. I hope this is the best method to achieve this. Please also let me know if there is any other way.

I have googled for the script but no success. Thanks for your help.
Posted by: anonymous_9363 13 years ago
Red Belt
0
P R E T T Y much like my post above yours intimates, Active Setup is the best way to propogate (or remove) logged-in user data when a package has no advertised entry-points.
Posted by: naveen.packager 13 years ago
Green Belt
0
Thanks VBScab. I want to achieve this during uninstallation. During installation i can use the sript file to be kept in installation folder and use active setup. But during uninstallation i need to clean all the files and folders related to the application. So i thought using vbscript would be the better way. Waiting for your advice.

Thanks once again.
Posted by: anonymous_9363 13 years ago
Red Belt
0
So:

- Create a new component
- Create a new GUID (use a blank Wise project as a cheat, if you don't have a GUID-generating script/tool)
- In your new component, create a new Active Setup key in HKLM and set the stub path to run your deletion script/batch file.
- Condition the component to be "installed" only during uninstallation

Next!
Posted by: pjgeutjens 13 years ago
Red Belt
0
Next!

see, now if only we weren't all sharing our knowledge for free out of the goodness of our heart you could have added

$$ KaChinggg $$ !!

but no... [:D]

PJ
Posted by: naveen.packager 13 years ago
Green Belt
0

Next!


Here it goes.........[:D]

I have tried conditioning the component using REMOVE~="ALL" and also MaintenanceMode="Remove". But the component is not getting installed during uninstalltion. I am using wps 7.

Please let me know if i am missing anything.

Thanks.
Posted by: avinalaff 13 years ago
Yellow Belt
0
Thanks Rave for that code snippet - i've been looking for something like this for a while now! [:D]
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