user856354
user856354

Reputation: 293

VBScript to uninstall a Windows 7 application

I am attempting to write a script that will uninstall a program when it is run. The problem is that the program will not have the exact same name each time, as it will have a version number attached. Is there anyway to grab the program name from a list, assuming it contains what I'm looking for? Then use that name to finish the uninstall?

The only uninstall function that I've found is:

strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 

Set colSoftware = objWMIService.ExecQuery _ 
    ("Select * from Win32_Product Where Name = 'Personnel database'") 

For Each objSoftware in colSoftware 
    objSoftware.Uninstall() 
Next 

Upvotes: 1

Views: 6946

Answers (1)

Helen
Helen

Reputation: 97962

You can use the LIKE operator instead of = in your query to test the product name against a pattern, like this:

Set colSoftware = objWMIService.ExecQuery _ 
    ("Select * from Win32_Product Where Name LIKE '%Personnel database%'") 

Upvotes: 1

Related Questions