While learning the K1000 unit, I had started to play with the Uninstall Wizard to uninstall unwanted software across my network.  The issue started happening where I would have to build an uninstaller for each and every version of software.  Particularly, I was trying to uninstall toolbars from everyones machine as they are unwanted and sneak on at every possible turn.  

As you can imagine or have experience with, this is time consuming.  Making sure you have each version accounted for, creating multiple groups for your script distribution etc.  Not to mention the clutter this adds to your scripting page.  I set out to find something better and more universal.

After some quick searching, I came across a perfect script for this task, it had all that I needed:

  1. A universal search string
  2. x86 and x64 compatible
  3. Simple to use

What information you need:

  1. Name or Portion of the name of the software to be removed ie. Google Toolbar, Bing Toolbar etc.
  2. Is it 32bit or 64bit?  Best way to tell, is it in “Program Files (x86)” or in “Program files”
    1. If it’s in “Program Files (x86)” its 32 bit, if in “Program Files” its 64 bit

There are 3 lines in the middle of this code that ask for the above information.  Without postin the whole script, this is the only content you are looking for.


‘SetApplicationPathItems "32-bit"
'SetApplicationPathItems "64-bit"
‘RemoveCurrentInstalls "xxxxxxx”


The first 2 lines ask, “is it 32 or 64bit?” Remove the quote from the front of the line you want to activate and leave the other unedited.  Then remove the quote from the “RemoveCurrentInstalls” line and replace “xxxxxxx” with the application of your choice.  Here is an example to remove 32bit google toolbar installation.


SetApplicationPathItems "32-bit"
'SetApplicationPathItems "64-bit"
RemoveCurrentInstalls "Google Toolbar"


This script is now ready.  Save it as a .vbs file and upload/setup your script parameters in the K1000 box under the scripting section.  I have a verify and Launch setup for the script to make sure the directoy exists and if it does, continue with the uninstall.  Shown below:




There you have it.  You can now set an uninstall script once for each product you want to uninstall.  You will have to generate separate scripts for each additional software you want to remove by changing the “RemoveCurrentInstalls” variable. Also make sure you use your smart lables to specify your vitims, er, target machines Wink

Here is the full code:

'LAST MODIFIED ON: 03/15/2011 by Rick {lucidation@hotmail.com}

'DISCLAIMER: This script is provided "as is" with all faults. The author cannot be held liable for any indirect, special, incidental, consequential, or exemplary damages arising out of or in any way relating to the use of this script, including without limitation damages for loss of goodwill, work stoppage, lost profits, loss of data, and computer failure or malfunction. You bear the entire risk as to the quality and performance of this script.

Option Explicit
const HKEY_LOCAL_MACHINE = &H80000002

Dim objWshShell, objWMI, WinDir, RegExp
Dim colWin32_ComputerSystem, objWin32_ComputerSystem
Dim strSoftwareName, strApplicationType
Dim strSystemType, strProgramFiles, strSoftwareRegistryKey

Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
WinDir = objWshShell.ExpandEnvironmentStrings("%windir%")
Set RegExp = new RegExp
RegExp.IgnoreCase = true

'On Error Resume Next

strSystemType = "x32"
Set colWin32_ComputerSystem = objWMI.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objWin32_ComputerSystem in colWin32_ComputerSystem
	If objWin32_ComputerSystem.SystemType = "x64-based PC" Then
		strSystemType = "x64"
	End If

'SetApplicationPathItems "32-bit"
'SetApplicationPathItems "64-bit"

'RemoveCurrentInstalls "xxxxxxxxxxxxxxxxxxxx"


' ~$~----------------------------------------~$~
' ~$~----------------------------------------~$~
Sub SetApplicationPathItems(strAppType)
'Setting the path to the correct ""Program Files"" folder and ""SOFTWARE"" registry key based on the application and OS type
strApplicationType = strAppType
If strSystemType = "x64" Then
	If strApplicationType = "64-bit" Then
		strSoftwareRegistryKey = "SOFTWARE"
		If UCase(Wscript.FullName) = UCase(WinDir & "\SysWOW64\WScript.exe") Then
			'Installing a 64-bit application on a 64-bit OS from a 32-bit wscript.exe process
			strProgramFiles = objWshShell.ExpandEnvironmentStrings("%ProgramW6432%")
			'Installing a 64-bit application on a 64-bit OS from a 64-bit wscript.exe process
			strProgramFiles = objWshShell.ExpandEnvironmentStrings("%ProgramFiles%")
		End If
		strSoftwareRegistryKey = "SOFTWARE\Wow6432Node"
		'Installing a 32-bit application on a 64-bit OS (the wscript.exe process type does not matter)
		strProgramFiles = objWshShell.ExpandEnvironmentStrings("%ProgramFiles(x86)%")
	End If
	strSoftwareRegistryKey = "SOFTWARE"
	'Installing a 32-bit application on a 32-bit OS from a 32-bit wscript.exe process
	strProgramFiles = objWshShell.ExpandEnvironmentStrings("%ProgramFiles%")
End If
End Sub

' ~$~----------------------------------------~$~
Sub RemoveCurrentInstalls(strValueCheck)
Dim objReg, strKeyPath, subkey, arrSubKeys, strValue, strCheckKey, intArrayCount, arrUninstallString, x
Dim strUninstallString, intStringLength, intUninstallReturn
strUninstallString = ""
arrUninstallString = Array()
intArrayCount = 0
strKeyPath = strSoftwareRegistryKey & "\Microsoft\Windows\CurrentVersion\Uninstall"
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
	strValue = ""
	strCheckKey = strKeyPath & "\" & subkey
	objReg.GetStringValue HKEY_LOCAL_MACHINE,strCheckKey,"DisplayName",strValue
	If Not IsNull(strValue) Then
		RegExp.pattern = strValueCheck
		If (RegExp.test (strValue) = TRUE) Then
			' Attempts to obtain the UninstallString for the matching string.
			objReg.GetStringValue HKEY_LOCAL_MACHINE,strCheckKey,"UninstallString",strValue
			reDim preserve arrUninstallString(UBound(arrUninstallString) +1)
			arrUninstallString(intArrayCount) = strValue
			intArrayCount = intArrayCount + 1
		End If
	End If
For x = LBound(arrUninstallString) to UBound(arrUninstallString)
	strUninstallString = arrUninstallString(x)
	If UCase(Left(strUninstallString, 14)) = UCase("MsiExec.exe /I") Then
		'Adjusting the uninstall string to fix known oddities
		intStringLength = Len(strUninstallString)
		strUninstallString = Left(strUninstallString, 13) & "X " & Right(strUninstallString, intStringLength - 14)
	End If
	intUninstallReturn = objWshShell.Run (strUninstallString & " /quiet /norestart", 1, True)
End Sub


I do not take credit for this script.  It was freely available on the web from here. http://myitforum.com/cs2/blogs/rbennett806/scripts/RemoveCurrentInstalls.txt



  1. Create a generic script that you can duplicate and only have to change a few lines like verify and vbs name.
  2. Keep a common naming convention so they group the same in the script view as in “Uninstall – XXXXX”
  3. Test Test Test
  4. Rollout to your users