• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 616
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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