Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to remove software using window scripting

Posted on 2006-10-31
6
Medium Priority
?
3,160 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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 6

Accepted Solution

by:
DeadlyTrev earned 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Integration Management Part 2
Suggested Courses

916 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