Solved

how to remove software using window scripting

Posted on 2006-10-31
6
3,157 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
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…

710 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