[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 402
  • Last Modified:

How to uninstall applications by GUID?

Hi Folks, I have some code to uninstall applications by GUID, which works.

Now I have a textfile with about ten GUIDS and like to modify the script so that it reads the textfile, checks whether the application is installed (by GUID) and if so, uninstall the application and afterwards give some feedback.

Hope someone can help me out.

Regards Peter
Set oWMIroot = GetObject("WinMgmts:root/cimv2")
Set oWMIColl = oWMIroot.ExecQuery("Select IdentifyingNumber, Name  FROM Win32_Product") 
 
For Each oWMIval In oWMIColl
	If oWMIval.IdentifyingNumber = ("{845A8DB9-8802-4FD3-9FE3-938A6C46A2EC}") Then
	WScript.Echo UninstallByGuid(oWMIval.IdentifyingNumber)
	End If		
Next
 
Function UninstallByGUID(sGUID)   
	 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
PeterdeB
Asked:
PeterdeB
  • 2
1 Solution
 
yehudahaCommented:
change this lines as need:

Set objlist = objfso.OpenTextFile("c:\list.txt", ForReading) -- > list of guid
Set objlog = objfso.CreateTextFile("c:\log.txt", ForWriting) -->> log file
Const ForReading = 1
Const ForWriting = 2
  
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set objlog = objfso.CreateTextFile("c:\log.txt", ForWriting)
 
Do Until objlist.AtEndOfStream
intgui = objlist.ReadLine
Set oWMIroot = GetObject("WinMgmts:root/cimv2")
Set oWMIColl = oWMIroot.ExecQuery("Select IdentifyingNumber, Name  FROM Win32_Product") 
 
For Each oWMIval In oWMIColl
        If oWMIval.IdentifyingNumber = (intgui) Then
        objlog.WriteLine UninstallByGuid(oWMIval.IdentifyingNumber) & vbcrlf
        End If          
Next 
Loop
 
Function UninstallByGUID(sGUID)   
         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
 
yehudahaCommented:
the list file need to be example:

"{845A8DB9-8802-4FD3-9FE3-938A6C46A2EC}"
"{845A8DB9-8802-4FD3-9FE3-938A6C46A2EC}"
"{845A8DB9-8802-4FD3-9FE3-938A6C46A2EC}"
0
 
PeterdeBAuthor Commented:
Thank you!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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