Login with Facebook

Friday, May 15, 2009

Uninstall Products using VB script

The below lines are for VBS script file you can use to uninstall

1

strComputer = "."

2

Set objWMIService = GetObject("winmgmts:" _

3

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

4

Set colSoftware = objWMIService.ExecQuery _

5

("SELECT * FROM Win32_Product WHERE Vendor = 'Hewlett-Packard'")

6

For Each objSoftware in colSoftware

7

objSoftware.Uninstall()

8

Next

in Line 1 you define variable called strComputer which is the computer you would like to execute this script against, in this case the value is “.” so this means localhost (locally)

Line 2 is to define Variable named objWMIService and to call WMI functions which is defined by winmgmts:

in the background the system loads Wbemdisp.dll which contains the Scripting Library functions

In VBS script they always split the functions in multiple lines although it can be used as one line, anyway

Line 3 which privilege level will be used in access the WMI

impersonationLevel=impersonate then the computer we are connecting to  which is strComputer  variable then the WMI class location "\root\cimv2”

Line 4 and 5 is one line but we use _ underscore to allow go to the next line (something like escape character) line 4 we define variable to contain the previously called data plus the function we are interested to call like query the WMI we use ExecQuery function. in line 5 we type our WMI QUERY Language where we select all columns available in class name win32_product and for not displaying all product we can filer the data by using  certain colmn value like name of the product or vendor

SELECT * FROM Win32_Product WHERE Vendor = 'Hewlett-Packard'

 

I have to sleep now

lets continue tomorrow

No comments:

Post a Comment