Link to home
Start Free TrialLog in
Avatar of RicohIT
RicohIT

asked on

Uninstall WebEx with VBS Script

Hi

I need a simple VBS script that uninstalls Webex from the computer silently. The command to uninstall it silently is as follows:

msiexec.exe /q /x "ptoolsni.msi"


Problem is that i am going to email this script to users on network so they can click it and get rid of webex. But users have different rights, some have admin rights and some doesnt. So how can i also add admin user and password encrypted so user wont be able to see that if he tries.

Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

user won't need special rights to uninstall this unless you created a GPO or other method like that which constraints that.all in all, they can run it from vbs like:Set wshShell = CreateObject("WScript.Shell")wshShell.Run "msiexec.exe", "/q /x \ptoolsni.msi", 0, trueor from bacth file:msiexec.exe /q /x "ptoolsni.msi"the thing is that you don't need to count on having the ptoolsni.msi file to unnistall, cause you can get the installation product string from the registry and use the following:msiexec.exe /q /x {1234-1234-1234-2134}{1234-1234-1234-2134} is the uninstall GUID which mapped with the aformentioned product.check the script i've posted.it support both 32bit and 64bit machines (add another call for TryUninstall with X64_UNINSTALL_REGISTRY if required)
const X64_UNINSTALL_REGISTRY = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
const X32_UNINSTALL_REGISTRY = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"

TryUninstall "WebEx", X32_UNINSTALL_REGISTRY

Sub TryUninstall (program, RegistryUninstallKey)

	Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") 
	
	Wscript.Echo RegistryUninstallKey
	oReg.EnumKey HKEY_LOCAL_MACHINE, RegistryUninstallKey, arrSubKeys

	For Each subkey In arrSubKeys
		
		oReg.GetStringValue HKEY_LOCAL_MACHINE, subkey, "DisplayName", displayName
		
		if displayName = program then
			oReg.GetStringValue HKEY_LOCAL_MACHINE, subkey, "UninstallString", strUninstall
			
			if (strUninstall <> "") then
				if LCase(Left(strUninstall,6))="msiexec" then
					uninstallCmd = Replace(strUninstall, "/I{", "/X{") & " /q REMOVE=ALL" ' MSI installer
				else
					uninstallCmd = strUninstall & " /S /NCRC" 'assume NSIS installer
				end if
					
				Wscript.Echo uninstallCmd
				
				WshShell.Run(uninstallCmd)
			end if
			
			objTextFile.WriteLine(Trim(program) & " uninstalled.")
		end if
	Next
End Sub

Open in new window

i've added some logging to the script
const X64_UNINSTALL_REGISTRY = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
const X32_UNINSTALL_REGISTRY = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"

TryUninstall "WebEx", X32_UNINSTALL_REGISTRY

Sub TryUninstall (program, RegistryUninstallKey)
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objTextFile = objFSO.OpenTextFile ("c:\uninstall.log", ForWriting, True)
	
	Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") 
	
	Wscript.Echo RegistryUninstallKey
	oReg.EnumKey HKEY_LOCAL_MACHINE, RegistryUninstallKey, arrSubKeys

	For Each subkey In arrSubKeys
		
		oReg.GetStringValue HKEY_LOCAL_MACHINE, subkey, "DisplayName", displayName
		
		if displayName = program then
			oReg.GetStringValue HKEY_LOCAL_MACHINE, subkey, "UninstallString", strUninstall
			
			if (strUninstall <> "") then
				if LCase(Left(strUninstall,6))="msiexec" then
					uninstallCmd = Replace(strUninstall, "/I{", "/X{") & " /q REMOVE=ALL" ' MSI installer
				else
					uninstallCmd = strUninstall & " /S /NCRC" 'assume NSIS installer
				end if
					
				Wscript.Echo uninstallCmd
				
				WshShell.Run uninstallCmd, 0, true
			end if
			
			objTextFile.WriteLine(Trim(program) & " uninstalled.")
		end if
	Next
	
	objTextFile.Close
End Sub

Open in new window

Avatar of RicohIT
RicohIT

ASKER

Thanks for replying, but as i dont know anything about VBS i would like to ask u something. Am i suppose to paste it into notepad and save it as VBS and then just run it? or do i need to do some kind of modification? Webex which is installed on over 50 computers was installer thru SCCM, and i still believe u need admin rights to uninstall it. But still im gonna give it a try.
just copy and paste it in notepad and save it as .vbs
to run it from command line:
cscript thescript.vbs

installing via SCCM doesn't have any impact on the script as long as the installer file was .msi (windows installer) or nsis installer.

anyway, the uninstall string GUID in the registry is what makes the script works cause it doesn't depend on the installer file or the way the installer was built.

another thing,

you can run it from explorer:
right click-> open with- > Windows Based Script Host (see screenshot)

if you run it from command line, type the following:

cscript thescript.vbs > c:\thescript.log

then you can check the log file to see the result of operation.
Untitled.jpg
Avatar of RicohIT

ASKER

So ill have users just dubble click it and it will uninstall Webex on their computer regardless of their rights being admin or not. Hmmm, lets give it a try.
Avatar of RicohIT

ASKER

i get the following error while executing the vbs file.


error.bmp
sorry, took it from another script of mine.
change line 8 from:
Set objTextFile = objFSO.OpenTextFile ("c:\uninstall.log", ForWriting, True)


to:
Set objTextFile = objFSO.CreateTextFile ("c:\uninstall.log", ForWriting, True)
here's an updated script for you:
const X64_UNINSTALL_REGISTRY = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
const X32_UNINSTALL_REGISTRY = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"

TryUninstall "Acrobat.com", X32_UNINSTALL_REGISTRY

Sub TryUninstall (program, RegistryUninstallKey)
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objTextFile = objFSO.CreateTextFile ("c:\uninstall.log", 2, True)
	
	Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") 
	
	oReg.EnumKey HKEY_LOCAL_MACHINE, RegistryUninstallKey, arrSubKeys

	For Each subkey In arrSubKeys
		
		oReg.GetStringValue HKEY_LOCAL_MACHINE, subkey, "DisplayName", displayName
		
		if displayName = program then
			oReg.GetStringValue HKEY_LOCAL_MACHINE, subkey, "UninstallString", strUninstall
			
			if (strUninstall <> "") then
				if LCase(Left(strUninstall,6))="msiexec" then
					uninstallCmd = Replace(strUninstall, "/I{", "/X{") & " /q REMOVE=ALL" ' MSI installer
				else
					uninstallCmd = strUninstall & " /S /NCRC" 'assume NSIS installer
				end if
					
				WshShell.Run uninstallCmd, 0, true
			end if
			
			objTextFile.WriteLine(Trim(program) & " uninstalled.")
		end if
	Next
	
	objTextFile.Close
End Sub

Open in new window

Avatar of RicohIT

ASKER

remember that im using a user now with limited rights, and creating a file on C: would deffinetly not work. Is creating a log file neccessary?
actually no, and you can change it to temporary file such as c:\windows\temp
Avatar of RicohIT

ASKER

First i get this pop up box where i press OK, ,then i get an error again.


error2.bmp
i've updated the script.
what the error says in english?
Avatar of RicohIT

ASKER

the object is not a collection
here's the upated script:
const HKEY_LOCAL_MACHINE = &H80000002
const X64_UNINSTALL_REGISTRY = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
const X32_UNINSTALL_REGISTRY = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"

TryUninstall "Acrobat.com", X32_UNINSTALL_REGISTRY

Sub TryUninstall (program, RegistryUninstallKey)
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objTextFile = objFSO.CreateTextFile ("c:\uninstall.log", 2, True)
	
	Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") 
	
	oReg.EnumKey HKEY_LOCAL_MACHINE, RegistryUninstallKey, arrSubKeys

	For Each subkey In arrSubKeys
		
		oReg.GetStringValue HKEY_LOCAL_MACHINE, subkey, "DisplayName", displayName
		
		if displayName = program then
			oReg.GetStringValue HKEY_LOCAL_MACHINE, subkey, "UninstallString", strUninstall
			
			if (strUninstall <> "") then
				if LCase(Left(strUninstall,6))="msiexec" then
					uninstallCmd = Replace(strUninstall, "/I{", "/X{") & " /q REMOVE=ALL" ' MSI installer
				else
					uninstallCmd = strUninstall & " /S /NCRC" 'assume NSIS installer
				end if
					
				WshShell.Run uninstallCmd, 0, true
			end if
			
			objTextFile.WriteLine(Trim(program) & " uninstalled.")
		end if
	Next
	
	objTextFile.Close
End Sub

Open in new window

Avatar of RicohIT

ASKER

i get the same error, on line 15 character 2,  Object is not a collection

Something wrong with this line i guess:   For Each subkey In arrSubKeys
can you post your script?
Avatar of RicohIT

ASKER


const HKEY_LOCAL_MACHINE = &H80000002
const X64_UNINSTALL_REGISTRY = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
const X32_UNINSTALL_REGISTRY = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"

TryUninstall "Acrobat.com", X32_UNINSTALL_REGISTRY

Sub TryUninstall (program, RegistryUninstallKey)
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objTextFile = objFSO.CreateTextFile ("c:\windows\temp\uninstall3.log", 2, True)
	
	Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") 
	
	oReg.EnumKey HKEY_LOCAL_MACHINE, RegistryUninstallKey, arrSubKeys

	For Each subkey In arrSubKeys
		
		oReg.GetStringValue HKEY_LOCAL_MACHINE, subkey, "DisplayName", displayName
		
		if displayName = program then
			oReg.GetStringValue HKEY_LOCAL_MACHINE, subkey, "UninstallString", strUninstall
			
			if (strUninstall <> "") then
				if LCase(Left(strUninstall,6))="msiexec" then
					uninstallCmd = Replace(strUninstall, "/I{", "/X{") & " /q REMOVE=ALL" ' MSI installer
				else
					uninstallCmd = strUninstall & " /S /NCRC" 'assume NSIS installer
				end if
					
				WshShell.Run uninstallCmd, 0, true
			end if
			
			objTextFile.WriteLine(Trim(program) & " uninstalled.")
		end if
	Next
	
	objTextFile.Close
End Sub

Open in new window

try
const HKEY_LOCAL_MACHINE = &H80000002
const X64_UNINSTALL_REGISTRY = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
const X32_UNINSTALL_REGISTRY = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"

TryUninstall "Acrobat.com", X32_UNINSTALL_REGISTRY

Sub TryUninstall (program, RegistryUninstallKey)
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objTextFile = objFSO.CreateTextFile ("c:\windows\temp\uninstall3.log", 2, True)
	
	Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") 
	
if oReg.EnumKey(HKEY_LOCAL_MACHINE, RegistryUninstallKey, arrSubKeys) =0 then

	For Each subkey In arrSubKeys
		
		oReg.GetStringValue HKEY_LOCAL_MACHINE, subkey, "DisplayName", displayName
		
		if displayName = program then
			oReg.GetStringValue HKEY_LOCAL_MACHINE, subkey, "UninstallString", strUninstall
			
			if (strUninstall <> "") then
				if LCase(Left(strUninstall,6))="msiexec" then
					uninstallCmd = Replace(strUninstall, "/I{", "/X{") & " /q REMOVE=ALL" ' MSI installer
				else
					uninstallCmd = strUninstall & " /S /NCRC" 'assume NSIS installer
				end if
					
				WshShell.Run uninstallCmd, 0, true
			end if
			
			objTextFile.WriteLine(Trim(program) & " uninstalled.")
		end if
	Next
	end if
	objTextFile.Close
End Sub

Open in new window

Avatar of RicohIT

ASKER

i will try it tommowor and give u a reply. By the way the string i gave u for uninstalling the program was wrong. I have the right string at work and i will try it tommorow.
Avatar of RicohIT

ASKER

Oki dude, i think iv solved the problem my self. I created a bat file for this and used lsrunas.exe to have bat file remember the password so it doesnt prompt for password every time you execute it. Password was written in plain text though, but i converted the bat file to exe file so people wont see the password by editing it. Im giving you the points because of your effort. Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RicohIT

ASKER

found a solution myself, but thanks for the effort