mrcc23 Posted April 5, 2006 Posted April 5, 2006 Is there a way to make it so if windows finds a certain registery key it will delete it automatically?
gunsmokingman Posted April 5, 2006 Posted April 5, 2006 Yes you can use a VBS script to do that.This VBS script writes to the registry then checks for the value then deletes the value.I have set it so it has message boxes popup at each stage.Save As Test_Write_Check_Delete.vbsConst HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion" strValueTest = "Test Value" : strValueName = "Test Value" Dim Act : Set Act = CreateObject("Wscript.Shell") Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv") objRegistry.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValueTest '''' VALUE THAT GET WRITTEN TO THE REG MsgBox "The Test Write To The Registry Was Written" & vbCrLf & "Press Key To Continue", 0 + 48, "Test Reg Write" objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue '''' VALUE THAT IT CHECKS FOR If IsNull(strValue) Then '''' CHECK FOR THE REG VALUE MsgBox "The Test Failed And Nothing Was Written", 0 + 48, "Test Failed" '''' VALUE IS NOT THERE Else '''' THE VALUE IS THERE ZZ1 = MsgBox ("Confirm Test Write Worked" & vbCrLf & "Did You Want To Open The Registry?" & vbCrLf &_ "To Check Before It Deleted" & vbCrLf & "Press Yes To Open Reg Edit" & vbCrLf &_ "Press No To Just Delete The Value" , 4 + 32, "Confirm Or Delete Value") If ZZ1 = 6 Then '''' YES CHECK THE REG FOR THE VALUE USING REGEDIT.EXE MsgBox "Open This Key In Reg Edit To Check Before Delete" & vbCrLf &_ "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" & strValue, 0 + 32, "Reg Value" Act.Run("Regedit.exe"),1,True : MsgBox "Press Key To Continue", 0 + 32, "Delete Value" objRegistry.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue '''' DELETE THE REG VALUE End If '''' NO JUST DELETE THE VALUE WITHOUT OPENING REGEDIT.EXE If ZZ1 = 7 Then : objRegistry.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue : End If End If Act.Run("Regedit.exe") ''' REOPEN REG EDIT AND SEE THE KEY IS GONEHere are some link that will help you Work The Registry using VBS script
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now