Solved

Uninstall WebEx with VBS Script

Posted on 2010-08-26
23
1,028 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
i get the following error while executing the vbs file.


error.bmp
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
actually no, and you can change it to temporary file such as c:\windows\temp
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:RicohIT
Comment Utility
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
Comment Utility
i've updated the script.
what the error says in english?
0
 

Author Comment

by:RicohIT
Comment Utility
the object is not a collection
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
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
Comment Utility
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
Comment Utility
can you post your script?
0
 

Author Comment

by:RicohIT
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
10x alot...
0
 

Author Closing Comment

by:RicohIT
Comment Utility
found a solution myself, but thanks for the effort
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now