Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Uninstall WebEx with VBS Script

Posted on 2010-08-26
23
1,097 Views
Last Modified: 2012-06-27
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
Comment
Question by:RicohIT
  • 12
  • 11
23 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 33531254
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
 
LVL 42

Expert Comment

by:sedgwick
ID: 33531291
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
 

Author Comment

by:RicohIT
ID: 33531539
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 42

Expert Comment

by:sedgwick
ID: 33531591
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
 
LVL 42

Expert Comment

by:sedgwick
ID: 33531630
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
 

Author Comment

by:RicohIT
ID: 33531660
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
 

Author Comment

by:RicohIT
ID: 33531754
i get the following error while executing the vbs file.


error.bmp
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 33531791
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
 
LVL 42

Expert Comment

by:sedgwick
ID: 33531828
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
 

Author Comment

by:RicohIT
ID: 33531853
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
 
LVL 42

Expert Comment

by:sedgwick
ID: 33531870
actually no, and you can change it to temporary file such as c:\windows\temp
0
 

Author Comment

by:RicohIT
ID: 33531982
First i get this pop up box where i press OK, ,then i get an error again.


error2.bmp
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 33532053
i've updated the script.
what the error says in english?
0
 

Author Comment

by:RicohIT
ID: 33532281
the object is not a collection
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 33532307
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
 

Author Comment

by:RicohIT
ID: 33532384
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
 
LVL 42

Expert Comment

by:sedgwick
ID: 33532406
can you post your script?
0
 

Author Comment

by:RicohIT
ID: 33532450

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
 
LVL 42

Expert Comment

by:sedgwick
ID: 33549050
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
 

Author Comment

by:RicohIT
ID: 33554894
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
 

Author Comment

by:RicohIT
ID: 33565290
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
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 33565433
10x alot...
0
 

Author Closing Comment

by:RicohIT
ID: 33565962
found a solution myself, but thanks for the effort
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question