Solved

how to remove software using window scripting

Posted on 2006-10-31
6
3,153 Views
Last Modified: 2008-01-09
Hi, .Net Experts,

I know this question may not belong to here, but I could not find a better place to ask.

My network admin has asked me to come up with a piece of windows scripting, which will be saved as myUninstall.bat on clients' desktop machines (OS win2k/win xp pro).

When it is run, it should work as if you were going through control panel, add/remove programs, then remove.

My google searched led me to following microsoft link.
http://www.microsoft.com/technet/scriptcenter/guide/sas_cpm_oxbm.mspx?mfr=true

And here is the sample script from it:

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

I have changed line 1 and 5 as follow, where wks126.myCompany.com is the machine name as seen under My Computer, and c:\Program Files\xyz\xyz.exe is the executable I want to remove.

strComputer = "wks126.myCompany.com"
("SELECT * FROM Win32_Product WHERE Name = 'C:\Program Files\xyz\xyz.exe '")

Are they all the changes I have to make? and the script will run as design?

Thanks!
0
Comment
Question by:ommer
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

by:DeadlyTrev
ID: 17846906
You can leave strComputer as ".".   A single period indicates the current machine.
0
 

Author Comment

by:ommer
ID: 17849601
Thanks! That helps me.

But the other part that scares me is that they said if the Where did not find any thing, the script will remove every software on the machine.

Will my physical path to the exe identify the unique program I want to remove, or should I just use xyz as from xyz.exe to be the application name?
0
 

Author Comment

by:ommer
ID: 17849694
Also, I would think the value has to come from the registry, but I did not find it.

So before I do my deadly try, I like to hear some blessings from you guys out there, even your name is DeadlyTrev :)

Thanks!
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 6

Accepted Solution

by:
DeadlyTrev earned 125 total points
ID: 17872587
WMI will parse the registry to build the list of Win32_Product items.  Have a look at
    HKLM_SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
and look closely at the DisplayName values.  This is the value that Win32_Product.Name will match.

'Personnel Database' is more likely to be the value you want rather than 'C:\Program Files\xyz\xyz.exe'

DT.

PS.
If you leave the WHERE clause out of your code then it will try and uninstall everyting  :-)
PPS.
It can takes a surprising amount of time for WMI to work via script so be patient after you execute it.
0
 

Author Comment

by:ommer
ID: 17881127
Great, thanks! I found the displayNAME I want. Well, it took me a while to figure out HKLM = HKEY_Local_Machine, I thought it was a typo at first.
0
 
LVL 6

Expert Comment

by:DeadlyTrev
ID: 17882828
HKLM is a shorthand, also HKCU, etc.

There was a typo, anyway ...  should have been HKLM\SOFTWARE\Micro...
                                                                             ^

Glad you've worked it out.  Another solution is to execute "MSIExec /u {GUID} /qn"  ... etc.  You'll find the appropriate ProductCode GUID in the same registry location.  Useful if you need to uninstall a specific version of a package that has been installed multiple times.

Cheers!
DT.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

786 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