"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
--