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.
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)
Please log in to answer
Posted by:
Rave
17 years ago
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
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:
veday001
16 years ago
Posted by:
eddysj
14 years ago
'*******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
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
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
Posted by:
naveen.packager
13 years ago
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.
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
Posted by:
naveen.packager
13 years ago
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.
Thanks once again.
Posted by:
anonymous_9363
13 years ago
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!
- 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
Posted by:
naveen.packager
13 years ago
Posted by:
avinalaff
13 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.