Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Re: Script to find the presence of a software

Reply
Thread Tools Display Modes

Re: Script to find the presence of a software

 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      02-24-2009

"coolguy123" <> wrote in message
news:...
>
> Hi,
>
> I need a script that finds the presence of a particular software (let
> us say MS Office ) in all the machines listed in a text file. I have a
> script which gives the output of all installed softwares in local
> computer. Can someone tell me what are the modifications i must do in
> this script to get the result for my scenario.
>
> ' Script To get installed software info and save it to a text file.
> '
> strHost = "."
>
> Const HKLM = &H80000002
> Set objReg = GetObject("winmgmts://" & strHost & _
> "/root/default:StdRegProv")
> Const strBaseKey = _
> "Software\Microsoft\Windows\CurrentVersion\Uninsta ll\"
> objReg.EnumKey HKLM,strBaseKey,arrSubKeys
>
> For Each strSubKey In arrSubKeys
> intRet = objReg.GetStringValue(HKLM,strBaseKey & strSubKey,_
> "DisplayName",strValue)
> If intRet <> 0 Then
> intRet = objReg.GetStringValue(HKLM,strBaseKey & strSubKey,_
> "QuietDisplayName",strValue)
> End If
> If (strValue <> "") and (intRet = 0) Then
> set fs = CreateObject("Scripting.FileSystemObject")
> logfile = "C:\Software.txt"
> set handle = fs.OpenTextFile(logfile,8,true)
>
>
> softwareName = strValue
> handle.WriteLine softwareName
> handle.close
> End If
> Next
>


I would suggest something similar to:
=========
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("SELECT * FROM Win32_Product WHERE Name = 'MyApp'")
=========
Otherwise, you would need to check for the application name in the loop
where you enumerate arrSubKeys. Perhaps:
=======
set fs = CreateObject("Scripting.FileSystemObject")
logfile = "C:\Software.txt"
set handle = fs.OpenTextFile(logfile,8,true)
For Each strSubKey In arrSubKeys
intRet = objReg.GetStringValue(HKLM,strBaseKey & strSubKey,_
"DisplayName",strValue)
If intRet <> 0 Then
intRet = objReg.GetStringValue(HKLM,strBaseKey & strSubKey,_
"QuietDisplayName",strValue)
End If
If (strValue <> "") and (intRet = 0) Then
If (strValue = "MyApp") Then
softwareName = strValue
handle.WriteLine softwareName
End If
End If
Next
handle.close
======
I also moved the opening and closing of the log file outside the loop. It
only needs to be done once, not for every strSubKey in arrSubKeys. In any
case, you will need test to see exactly what the application name is in your
case.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Software Can't Find Harddrive JamesJ Virtual PC 6 03-09-2008 01:58 PM
Web presence and SBS2003R2 guzzifrank Windows Small Business Server 4 09-30-2007 07:17 PM
how to find out who installed software mtler Windows Server 1 03-08-2006 12:29 PM
Re: Find PID in vbs script Harvey Colwell Scripting 1 07-29-2003 08:44 PM
Re: Find PID in vbs script Yoann Roman Scripting 3 07-29-2003 11:35 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59