/build/static/layout/Breadcrumb_cap_w.png

Uninstall a family of software versions, not each version separately

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
Next

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

'RemoveCurrentInstalls "xxxxxxxxxxxxxxxxxxxx"

Wscript.Quit





' ~$~----------------------------------------~$~
'        STANDARD FUNCTIONS & SUBROUTINES
' ~$~----------------------------------------~$~
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%")
		Else
			'Installing a 64-bit application on a 64-bit OS from a 64-bit wscript.exe process
			strProgramFiles = objWshShell.ExpandEnvironmentStrings("%ProgramFiles%")
		End If
	Else
		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
Else
	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
Next
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)
Next
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

 

Tips/Suggestions:

  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

Comments

  • This scripts works perfectly but i would like to know how can I run a script to remove Spotify from workstations using this script. Spotify does not install into Programs or Program (x86) directory only under user profile. I would like to remove Spotify from our network? - gpuk1234 10 years ago
    • You seem unsure as to whether or not you actually want to remove Spotify from your network. - giggsteve8 10 years ago
    • I created a new blog for you on this. Let me know if you need any help.

      http://www.itninja.com/blog/view/uninstall-a-non-standard-application-that-doesn-t-install-to-program-files - spinuzer 10 years ago
  • Very good! Thanks for the input!! - brunocardoso 10 years ago
This post is locked

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ