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

Uninstalling Multiple Applications via VBScript

Hi all,

I am trying to create a VBScript that will uninstall multiple (13) applications silently (preferably uninstalling one after another continuously as per the script)  based on the application's GUID in the registry. I have attached an example of what I have so far.

My probelm is that it uninstalls App 1 just fine, but does not proceed from there. I am pretty sure it is something to do with my script coding.

I am new to VBscript, so if anyone could help me it would be greatly appreciated.

Cheers,

Craig
const HKLM = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
Set oShell = CreateObject("Wscript.Shell")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKLM,strKeyPath, aSubKeys
 
For Each key In aSubKeys
If key = "{0B5C7C36-3351-4FD8-A2A0-FD26B2D96C96}" Then
        oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
        oShell.Run strUninstall & " /qn",0,True
        ' App 1 Unintsallation
End If
       
        
If key = "{15A3BBD9-3472-46EB-8ADD-6D6EF6558AE9}" Then
        oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
        oShell.Run strUninstall & " /qn",0,True
        ' App 2 Unisnatallation
End if
 
 
If key = "{18723773-979B-4C20-B059-55EE95EE0188}}" Then
        oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
        oShell.Run strUninstall & " /qn",0,True
        ' App 3 Uninsatallation
End if
 
 
 
If key = "{1A48D216-0704-46BB-9A6A-3D092E635A83}" Then
		 oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
         oShell.Run strUninstall & " /qn",0,True
         ' App 4 Uninstallation        
End If
 
 
If key = "{1A48D216-0704-46BB-9A6A-3D092E635A83}" Then
		 oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
         oShell.Run strUninstall & " /qn",0,True
         'App 5 Uninstallation
End If
 
If key = "{E52DB94A-5F65-4568-8F45-E845C5B06E78}" Then
		 oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
         oShell.Run strUninstall & " /qn",0,True
         ' App 6 Uninstallation
End If
 
If key = "{7B7A94EA-A369-40B2-B97D-BEB34C2BA9DA}" Then
		 oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
         oShell.Run strUninstall & " /qn",0,True
         ' App 7 Uninstallation
End If
 
If key = "{E18E091D-0001-4C7E-BFDE-2DFB2B6875CD}" Then
		 oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
         oShell.Run strUninstall & " /qn",0,True
         ' App 8 Uninstallation
End If
 
If key = "{24D8509C-F973-4B2B-80B3-5FD1C461C776}" Then
		 oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
         oShell.Run strUninstall & " /qn",0,True
         'App 9 Uninstallation
End If
 
 
If key = "{EFAA3758-373C-4B68-8F6A-CC1DCCDD5CAA}" Then
		 oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
         oShell.Run strUninstall & " /qn",0,True
         'App 10 Uninstallation
End If
 
If key = "{5AC9E1C3-0964-48F8-8715-816D82BF66E5}" Then
		 oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
         oShell.Run strUninstall & " /qn",0,True
         'App 11 Uninstallation
End If
 
If key = "{6555BE32-6386-4130-BD38-8FF4E7A72440}" Then
		 oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
         oShell.Run strUninstall & " /qn",0,True
         'App 12 Uninstallation
End If
 
If key = "{ADADF5F8-4A42-444D-80AD-699E9D1CF1ED}" Then
		 oReg.GetStringValue HKLM, strKeyPath & "\" & key, "UninstallString", strUninstall
         oShell.Run strUninstall & " /qn",0,True
         'App 13 Uninstallation
End If
 
 
Next

Open in new window

0
Craig_Campbell
Asked:
Craig_Campbell
  • 4
  • 3
  • 2
  • +1
1 Solution
 
merowingerCommented:
Does the user has admin rights?
Could you run the command from the first application manually if the unsintall complete, idle or waits for response?
First of all do an visisble unisntall with changing 0 to 1 (oShell.Run strUninstall & " /qn",1,True)
0
 
Craig_CampbellAuthor Commented:
Thanks Merowinger,

Yes, the users who will run this script will have domain admin rights.

I changed the value you said from '0' to '1', but the same thing is happening (ie. no prompts are coming up to uninstall the applications and they are not uninstalling).

And yes, the uninstallation completes for all products without user intercation during the manual uninstall process as well.
0
 
yehudahaCommented:
try this
const HKLM = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
Set oShell = CreateObject("Wscript.Shell")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKLM,strKeyPath, aSubKeys
 
For Each key In aSubKeys
WScript.Echo UninstallByGuid(key) 
Next
 
msgbox "done"
 
Function UninstallByGUID(sGUID)   
Set oWMIroot = SWBemlocator.ConnectServer(strComputer,"root\CIMV2") 
        Set oWMIColl = oWMIroot.ExecQuery("Select * FROM Win32_Product Where IdentifyingNumber = '" & sGUID & "'") 
         For Each oWMIval In oWMIColl
         oWMIval.Uninstall() 
         UninstallByGUID = "Removal of " & oWMIval.Name & " complete (" & err.number & ")"
         Next 
         If UninstallByGUID = "" Then UninstallByGUID = "Application GUID not found."        
 End Function
 

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
yehudahaCommented:
don't uswe it yet !!!
0
 
yehudahaCommented:
fix the script that will fit to all of your guid

like my example in the script

If key = "{0B5C7C36-3351-4FD8-A2A0-FD26B2D96C96}" Then
WScript.Echo UninstallByGuid(key)
End If
const HKLM = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
Set oShell = CreateObject("Wscript.Shell")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKLM,strKeyPath, aSubKeys
 
For Each key In aSubKeys
 
If key = "{0B5C7C36-3351-4FD8-A2A0-FD26B2D96C96}" Then
WScript.Echo UninstallByGuid(key) 
End If
 
Next
 
msgbox "done"
 
Function UninstallByGUID(sGUID)   
Set oWMIroot = SWBemlocator.ConnectServer(strComputer,"root\CIMV2") 
        Set oWMIColl = oWMIroot.ExecQuery("Select * FROM Win32_Product Where IdentifyingNumber = '" & sGUID & "'") 
         For Each oWMIval In oWMIColl
         oWMIval.Uninstall() 
         UninstallByGUID = "Removal of " & oWMIval.Name & " complete (" & err.number & ")"
         Next 
         If UninstallByGUID = "" Then UninstallByGUID = "Application GUID not found."        
 End Function
 

Open in new window

0
 
Craig_CampbellAuthor Commented:
Thanks yehudaha,

When I run the script above (with another GUID of course) it comes up with an error:

Object Required: 'SWBemlocator'

I have attached an image of the error. Do you know what this means?
error.jpg
0
 
merowingerCommented:
add this line below the line strComputer = "."

Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
0
 
Craig_CampbellAuthor Commented:
A great script that works perfectly. Thank you very much for your help yehudaha.
0
 
yehudahaCommented:
glad to help thanks for the grade
0
 
BechumCommented:
Hello,

I'm testing this script but i need to uninstall a program that not have a key {xxx-xxx-xxx} but a name like UltraVNC.
I replace "{xxxxx-xxxx-xxxx}" by "UltraVNC" but when i run it i have a message 'Application GUID not found'.
Is it another string for application name ?

Excuse me for my little english and than'k for your help.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now