Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 614
  • Last Modified:

Delete registry key with VBS

Hi,

Just need a simple vbs script to delete registry key in windows

thanks
0
cooljam23
Asked:
cooljam23
1 Solution
 
Bob LambersonSoftware EngineerCommented:
cooljam23,
From vb help files...

DeleteSetting appname, section[, key]

Bob
0
 
Mark_FreeSoftwareCommented:

i found this example:



Deleting a Registry Key

Uses WMI to delete the registry key HKLM\SOFTWARE\System Admin Scripting Guide.

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\System Admin Scripting Guide"
 
oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath


Deleting Registry Values

Uses WMI to delete all the registry values under HKLM\SOFTWARE\System Admin Scripting Guide.

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\System Admin Scripting Guide"
strDWORDValueName = "DWORD Value Name"
strExpandedStringValueName = "Expanded String Value Name"
strMultiStringValueName = "Multi String Value Name"
strStringValueName = "String Value Name"
 
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strDWORDValueName
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strExpandedStringValueName
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strMultiStringValueName
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strStringValueName
0
 
vinnyd79Commented:

This will delete a key:

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.RegDelete "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\TestKey\"
Set WshShell = Nothing


This will delete a value:

Set WshShell = CreateObject("WScript.Shell")
WshShell.RegDelete "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\MyValue"
Set WshShell = Nothing
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now