Home All Groups Group Topic Archive Search About

Script to find the presence of a software

Author
24 Feb 2009 6:37 AM
coolguy123
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\Uninstall\"
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 -- coolguy123 ------------------------------------------------------------------------ coolguy123's Profile: http://forums.techarena.in/members/coolguy123.htm View this thread: http://forums.techarena.in/server-scripting/1129087.htmhttp://forums.techarena.in

Author
24 Feb 2009 4:02 PM
coolguy123
Can someone help me in this...? -- coolguy123 ------------------------------------------------------------------------ coolguy123's Profile: http://forums.techarena.in/members/coolguy123.htm View this thread: http://forums.techarena.in/server-scripting/1129087.htmhttp://forums.techarena.in
Are all your drivers up to date? click for free checkup

Author
24 Feb 2009 5:29 PM
Richard Mueller [MVP]
Show quote Hide quote
"coolguy123" <coolguy123.3o3pfb@DoNotSpam.com> wrote in message
news:coolguy123.3o3pfb@DoNotSpam.com...
>
> 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\Uninstall\"
> 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
--

Bookmark and Share

Post Thread options