Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Script to get installed software and server applications on remote servers

142 views
Skip to first unread message

Richard Mueller [MVP]

unread,
Mar 25, 2004, 12:43:18 PM3/25/04
to
A A wrote:

>
> How can i run this VBS script for many remote servers at the same time,i
think with input txt file but how???
>
> Thanks for your time.
> Greetings,
> A.A
>
>
> -------------------------
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.CreateTextFile("c:\scripts\software.tsv", True)
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set colSoftware = objWMIService.ExecQuery _
> ("Select * from Win32_Product")
> objTextFile.WriteLine "Name" & vbtab & _
> "Vendor" & vbtab & "Version"
> For Each objSoftware in colSoftware
> objTextFile.WriteLine objSoftware.Name & vbtab & _
> objSoftware.Vendor & vbtab & _
> objSoftware.Version
> Next
> objTextFile.Close
>
> -------------------------

Hi,

I used the code below. The file Machines.txt has the NetBIOS name of the
machines to report on, one machine name per line:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile("c:\MyFolder\Machines.txt", 1)
Set objOutputFile = objFSO.OpenTextFile("c:\MyFolder\Software.txt", 2, True,
0)

objOutputFile.WriteLine "Computer" & vbTab & "Name" & vbtab & _
"Vendor" & vbtab & "Version"

Do Until objInputFile.AtEndOfStream
strComputer = Trim(objInputFile.ReadLine)
If strComputer <> "" Then
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product")
For Each objSoftware in colSoftware
objOutputFile.WriteLine strComputer & vbTab & objSoftware.Name _
& vbtab & objSoftware.Vendor & vbtab & objSoftware.Version
Next
End If
Loop
objInputFile.Close
objOutputFile.Close
Wscript.Echo "Done"

--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--


Richard Mueller [MVP]

unread,
Mar 30, 2004, 7:56:15 PM3/30/04
to
LN wrote:

> Hi Richard,
> I tried your script, it works great. Except it doesn't list all software
installed the remote computers.
>
> Is there a limitation? Seems like max of 3 installed software are only
listed.

Hi,

There is not a limit on the number - I've seen machines with 8 or so apps
listed. However, the Win32_Product class only accounts for apps installed
with Windows Installer. You get a lot of info easily, but only because of
this limitation. To get info on other apps you would have to code a brute
force search of the registry and/or file system.

I believe I've seen code to enumerate the apps listed in the Add/Remove
Programs applet of Control Panel. If I find it I'll post, unless someone
else has it handy.

Richard Mueller [MVP]

unread,
Mar 30, 2004, 9:50:11 PM3/30/04
to

"Richard Mueller [MVP]" <rlmuelle...@ameritech.NOSPAM.net> wrote in
message news:uvIb1xrF...@TK2MSFTNGP10.phx.gbl...
I found this posting where Torgeir Bakken has code to enumerate apps in
Add/Remove Programs:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=3FB50333.E86C2746%40hydro.com

LN

unread,
Mar 31, 2004, 4:46:13 PM3/31/04
to
Thanks for the reference.

I did modify Torgeir's script to read from a text file a list of computers, and then loop thru and list the installed programs. However, I'm getting an error:

"Microsoft VBScript runtime error: Name redefined: 'HKLM'"

The current value set for HKLM is... HKLM = &H80000002

Not sure where to go next...? Any insights?


----- Richard Mueller [MVP] wrote: -----

Torgeir Bakken (MVP)

unread,
Mar 31, 2004, 4:54:07 PM3/31/04
to
LN wrote:

> Thanks for the reference.
>
> [snip] However, I'm getting an error:

>
> "Microsoft VBScript runtime error: Name redefined: 'HKLM'"
>
> The current value set for HKLM is... HKLM = &H80000002

Hi

Add this line at the top of your script:

Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE

and remove all other "Const HKLM = ..." lines in your script.


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/community/scriptcenter/default.mspx

Richard Mueller [MVP]

unread,
Mar 31, 2004, 4:56:12 PM3/31/04
to
Hi,

I see that Torgeir defined the constant in the function. You must have put
the function code in a loop. A "Const" statement can only be "executed"
once. Place the "Const" statement at the beginning of your script, where it
is encountered only once by the script engine.

--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--

"LN" <anon...@discussions.microsoft.com> wrote in message
news:CE6CA9B6-4B81-4271...@microsoft.com...

Torgeir Bakken (MVP)

unread,
Mar 31, 2004, 5:32:16 PM3/31/04
to
LN wrote:

> Ok, did as you suggested. Now I'm getting a "null"
>
> Here is the code perhaps you'll point out what I'm doing wrong.
> (snip)
Hi

You need to have all Function and Sub code outside any loops in your
script, and just make a callout to the Function in the loop.

Here is a rewritten version of your script, I have also added a ping
function to your code to check if the computers are online before
trying to make a WMI connection to them:


Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objInputFile = objFSO.OpenTextFile("e:\scripts\machines.txt", 1)
Set objOutputFile = objFSO.OpenTextFile _
("e:\scripts\getSw\Add-RemovePrograms.txt", 2, true, 0)

Do Until objInputFile.AtEndOfStream
strComputer = Trim(objInputFile.ReadLine)
If strComputer <> "" Then

If IsConnectible(strComputer, "", "") Then
objOutputFile.WriteLine "********** " & strComputer & " **********" _
& vbCrLf & InstalledApplications(strComputer)
Else
objOutputFile.WriteLine "********** " & strComputer & " **********" _
& vbCrLf & "-- COULD NOT CONNECT TO COMPUTER --" & vbCrLf

End If
End If
Loop

objInputFile.Close
objOutputFile.Close
Wscript.Echo "Done"


Function InstalledApplications(node)
Set oRegistry = _
GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& node & "/root/default:StdRegProv")
sBaseKey = _
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys)
For Each sKey In arSubKeys
iRC = oRegistry.GetStringValue( _
HKLM, sBaseKey & sKey, "DisplayName", sValue)
If iRC <> 0 Then
oRegistry.GetStringValue _
HKLM, sBaseKey & sKey, "QuietDisplayName", sValue
End If
If sValue <> "" Then
InstalledApplications = _
InstalledApplications & sValue & vbCrLf
End If
Next
End Function


Function IsConnectible(sHost, iPings, iTO)
' Returns True or False based on the output from ping.exe
'
' Author: Alex Angelopoulos/Torgeir Bakken
' Works an "all" WSH versions
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used

Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Dim oShell, oFSO, sTempFile, fFile

If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")

sTempFile = oFSO.GetSpecialFolder(2).ShortPath & "\" & oFSO.GetTempName

oShell.Run "%comspec% /c ping.exe -n " & iPings & " -w " & iTO _
& " " & sHost & ">" & sTempFile, 0 , True

Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
FailIfNotExist, OpenAsASCII)

Select Case InStr(fFile.ReadAll, "TTL=")
Case 0 IsConnectible = False
Case Else IsConnectible = True
End Select

fFile.Close
oFSO.DeleteFile(sTempFile)

End Function

0 new messages