Solved

how to remove software using window scripting

Posted on 2006-10-31
6
3,141 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ASP.net markup problem with table alignment 2 31
asp.net mvc5 3 37
How do I get the id from URL? 19 47
crm development 2 37
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now