create text file
set domain
set filter
for each object get computer name
for
get software info
next
next
close file
I was thinking of putting an if in there so that it will just go to next
lcomputer in the loop, but i do not know how.
thanks for the help
> Hi
> I am a bit stuck
> I have put together two scripts, one to list of all computers in a domain,
> and then next to enumerate all software and then output it all to text
> file. The problem is that it assumes all computers are up and running and
> will die if one is not.
> I basically have a script that is like this
> (snip)
Hi
Here is an example, I have also added a ping function to check if
the computers are online before trying to make a WMI connection to
them (the WMI connection is error handled as well):
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)
On Error Resume Next
Set oRegistry = _
GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& node & "/root/default:StdRegProv")
sBaseKey = _
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys)
If Err.Number = 0 And iRC = 0 Then
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
Else
InstalledApplications = "-- COULD NOT CONNECT TO COMPUTER --" _
& vbCrLf
End If
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
--
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
> You could add
>
> On Error Resume Next
>
> at the beginning of the script
> which basically causes the script to skip systems it can not reach
Thanks torgeir and blake, appreciate it.