• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1211
  • Last Modified:

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.

0
RicohIT
Asked:
RicohIT
  • 12
  • 11
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
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

0
 
Meir RivkinFull stack Software EngineerCommented:
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

0
 
RicohITAuthor Commented:
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Meir RivkinFull stack Software EngineerCommented:
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.

0
 
Meir RivkinFull stack Software EngineerCommented:
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
0
 
RicohITAuthor Commented:
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.
0
 
RicohITAuthor Commented:
i get the following error while executing the vbs file.


error.bmp
0
 
Meir RivkinFull stack Software EngineerCommented:
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)
0
 
Meir RivkinFull stack Software EngineerCommented:
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

0
 
RicohITAuthor Commented:
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?
0
 
Meir RivkinFull stack Software EngineerCommented:
actually no, and you can change it to temporary file such as c:\windows\temp
0
 
RicohITAuthor Commented:
First i get this pop up box where i press OK, ,then i get an error again.


error2.bmp
0
 
Meir RivkinFull stack Software EngineerCommented:
i've updated the script.
what the error says in english?
0
 
RicohITAuthor Commented:
the object is not a collection
0
 
Meir RivkinFull stack Software EngineerCommented:
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

0
 
RicohITAuthor Commented:
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
0
 
Meir RivkinFull stack Software EngineerCommented:
can you post your script?
0
 
RicohITAuthor Commented:

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

0
 
Meir RivkinFull stack Software EngineerCommented:
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

0
 
RicohITAuthor Commented:
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.
0
 
RicohITAuthor Commented:
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.
0
 
Meir RivkinFull stack Software EngineerCommented:
10x alot...
0
 
RicohITAuthor Commented:
found a solution myself, but thanks for the effort
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 12
  • 11
Tackle projects and never again get stuck behind a technical roadblock.
Join Now