Pages

Thursday, 23 July 2009

Delete Registry if its Empty - VBScript

On Error Resume next
Const HKEY_LOCAL_MACHINE = &H80000002
Set wsh1=createobject("Wscript.shell")


strKeyRoot = "SOFTWARE\Microsoft\Microsoft SQL Server"
strKeyRoot1 = "SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent"
strKeyRoot2 = "SOFTWARE\Microsoft\MSSQLServer\Client\SuperSocketNetLib\VIA"
strKeyRoot3 = "SOFTWARE\Microsoft\MSSQLServer\Client\SuperSocketNetLib"
strKeyRoot4 = "SOFTWARE\Microsoft\MSSQLServer\Client"
strKeyRoot5 = "SOFTWARE\Microsoft\MSSQLServer"
strKeyRoot6 = "SOFTWARE\Microsoft\SQL Redist\Setup"
strKeyRoot7 = "SOFTWARE\Microsoft\SQL Redist\1.00.000"
strKeyRoot8 = "SOFTWARE\Microsoft\SQL Redist"
strKeyRoot9 = "SOFTWARE\Microsoft\dasetup"
Set oReg=GetObject("winmgmts:root\default:StdRegProv")


oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyRoot, arrSubKeys
If IsNull(arrSubKeys) Then
wsh1.RegDelete "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\"
End If


oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyRoot1, arrSubKeys
If IsNull(arrSubKeys) Then
wsh1.RegDelete "HKLM\SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent\"
End If


oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyRoot2, arrSubKeys
If IsNull(arrSubKeys) Then
wsh1.RegDelete "HKLM\SOFTWARE\Microsoft\MSSQLServer\Client\SuperSocketNetLib\VIA\"
End If


oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyRoot3, arrSubKeys
If IsNull(arrSubKeys) Then
wsh1.RegDelete "HKLM\SOFTWARE\Microsoft\MSSQLServer\Client\SuperSocketNetLib\"
End If


oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyRoot4, arrSubKeys
If IsNull(arrSubKeys) Then
wsh1.RegDelete "HKLM\SOFTWARE\Microsoft\MSSQLServer\Client\"
End If


oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyRoot5, arrSubKeys
If IsNull(arrSubKeys) Then
wsh1.RegDelete "HKLM\SOFTWARE\Microsoft\MSSQLServer\"
End If


oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyRoot6, arrSubKeys
If IsNull(arrSubKeys) Then
wsh1.RegDelete "HKLM\SOFTWARE\Microsoft\SQL Redist\Setup\"
End If


oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyRoot7, arrSubKeys
If IsNull(arrSubKeys) Then
wsh1.RegDelete "HKLM\SOFTWARE\Microsoft\SQL Redist\1.00.000\"
End If


oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyRoot8, arrSubKeys
If IsNull(arrSubKeys) Then
wsh1.RegDelete "HKLM\SOFTWARE\Microsoft\SQL Redist\"
End If


oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyRoot9, arrSubKeys
If IsNull(arrSubKeys) Then
wsh1.RegDelete "HKLM\SOFTWARE\Microsoft\dasetup\"
End If


WScript.Quit

No comments:

Post a Comment