Solved

how to remove software using window scripting

Posted on 2006-10-31
6
3,155 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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