Monday, April 20, 2009

Universal scripted uninstall (XP)

Given the displayname value, this vbscript will go and find it in the registry and uninstall the corresponding program.

This is where it searches:

hklm\software\microsoft\windows\currentversion\uninstall



' arg 1 - displayname


if (wscript.arguments.count > 0 ) then

set shell = wscript.createobject("wscript.shell")
strcmd = "reg query hklm\software\microsoft\windows\currentversion\uninstall /s"

set oexec = shell.exec(strcmd)

temp = 0
parent = ""

do while not oexec.stdout.atendofstream

strline = oexec.stdout.readline


if len(strline) > 0 then
a=split(strline,vbtab)
if mid(trim(a(0)),1,4) = "HKEY" then
b = split(trim(a(0)),"\")
parent = b(ubound(b))
temp = 1
end if
alen = ubound(a) + 1
if alen >= 3 then
if trim(a(0)) = "DisplayName" and trim(a(2)) = wscript.arguments(0) and temp = 1 then
wscript.echo "msiexec /x " & parent & " /qn"
temp = 0
shell.exec("msiexec /x " & parent & " /qn")
exit do
end if

end if
end if
loop




end if

No comments:

Post a Comment