I am trying to scan my network using this script listed below to scan
a list of servers from a text file. I can scan a single computer just
fine but unable to get this to pull from a list of servers from a text
file. Any help would be greatly appreciated.






'On Error Resume Next directive is specified so that users
'are not bothered by potential operational errors with the script.
'On Error Resume Next
'Using both of these flags of the WbemFlagEnum enumeration
'makes a semisynchronous WMI call. See "Making a Semisynchronous Call"
'in the WMI SDK for more information.
Const wbemFlagReturnImmediately = 16
Const wbemFlagForwardOnly = 32
'WbemCimtypeEnum Enumerations used in the script
Const wbemCimtypeUint32 = 19
Const wbemCimtypeSint64 = 20
Const wbemCimtypeUint64 = 21
'Formatting and number conversion constants
Const HR = "----"
Const KB = 1024
Const MB = 1048576
Const GB = 1073741824

'Change this to the UNC path where inventory files should be created
'Anyone running this script must have read and write access to the
'path.
strInvFilePath = "E:\hw\"

'If each user will run this inventory file locally, do not change the
value
'of strComputer.
strComputer = "."

'Connect to WMI
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")

'Determine the OS because not all classes listed here are supported
'on all versions of the Windows operating systems
strProperties = "CreationClassName,Version,CSName,Caption"
Set objOS = objWMIService.ExecQuery _
("SELECT " & strProperties & " FROM Win32_OperatingSystem",_
,wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each Setting in objOS
strCreationClass = Setting.CreationClassName
intVersion = Setting.Version
strCSName = Setting.CSName
strCaption = Setting.Caption
Next

'Check for a file named after the computer. If it doesn't
'exist, then create a file that contains the computer's
'hardware inventory.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFileName = "HrdWrInv_" & strCSName & ".txt"
strFullName = objFSO.BuildPath(strInvFilePath, strFileName)
If (objFSO.FileExists(strFullName)) Then WScript.Quit
Set objFile = objFSO.CreateTextFile(strFullName)
'Write the Operating System name and version but nothing more.
'The goal is to collect hardware inventory, not software inventory
'and configuration information.
objFile.WriteLine("OSInformation:")
objFile.WriteLine("CreationClassName: " & strCreationClass)
objFile.WriteLine("ComputerName: " & strCSName)
objFile.WriteLine("Caption: " & strCaption)
objFile.WriteLine("Version: " & intVersion)

'The name property is automatically returned (because it's a key
value), so
'it's not absolutely necessary to specify it in strProperties
strProperties = _
"CreationClassName,Manufacturer,Model,Name,NumberofProcessors," & _
"SystemType,TotalPhysicalMemory"
QueryInstances "Win32_ComputerSystem",strProperties,"None"
'Page file information.
strProperties = _
"Name,MaximumSize"
QueryInstances "Win32_PageFileSetting",strProperties,"None"
'Physical memory information.
'Note, total memory is aggregated and listed with win32_computersystem
so there's
'no need to query the memory classes, such as
Win32_PhysicalMemoryArray or
'Win32_PhysicalMemory. However, if you need to find out how much
memory
'a computer will hold, it's useful to query Win32_PhysicalMemoryArray
as
'shown
strProperties = _
"MaxCapacity,CreationClassName"
QueryInstances "Win32_PhysicalMemoryArray",strProperties,"None"
'SCSI Disk controller information
strProperties = _
"Name,Manufacturer,Description,CreationClassName"
QueryInstances "Win32_SCSIController",strProperties,"None"
'IDE Disk controller information
strProperties = _
"Name,Manufacturer,Description,CreationClassName"
QueryInstances "Win32_IDEController",strProperties,"None"
'Phyiscal Media information
'Note, this class is only in XP (ver5) and the Windows
'Server 2003 family (ver5).
'Win98SE reports a version number of 4 (4.10.2222)
If Mid(intVersion,1,3) >= 5.1 Then
strProperties = _
"SerialNumber,CreationClassName"
QueryInstances "Win32_PhysicalMedia",strProperties,"None"
End If
'Logical Disk information
strProperties = _
"DriveType,Description,DeviceID,CreationClassName"
QueryInstances "Win32_LogicalDisk",strProperties,_
"DriveType!=3 AND DriveType !=4"
'Disk drive information
strProperties = _
"Caption,Description,DeviceID,InterfaceType," & _
"Manufacturer,MediaType,Model,Partitions,Size,CreationClassName"
QueryInstances "Win32_DiskDrive",strProperties,"None"
'Processor information
strProperties = _
"Manufacturer,MaxClockSpeed,ExtClock,ProcessorType," & _
"Revision,Version,CreationClassName"
QueryInstances "Win32_Processor",strProperties,"None"
'NIC information
strProperties = _
"Manufacturer,MACAddress,ProductName,AdapterType,CreationClassName"
QueryInstances "Win32_NetworkAdapter",strProperties,_
"AdapterType='Ethernet 802.3' AND ProductName !='Packet Scheduler
Miniport'"
'Monitor information
strProperties = _
"Description,MonitorType,CreationClassName"
QueryInstances "Win32_DesktopMonitor",strProperties,"None"
'Video adapter information
strProperties = _
"Name,MaxRefreshRate,AdapterRAM,CreationClassName"
QueryInstances "Win32_VideoController",strProperties,"None"
'Motherboard information
strProperties = _
"Description,Manufacturer,Product,CreationClassName"
QueryInstances "Win32_BaseBoard",strProperties,"None"
'BIOS information
strProperties = _
"Manufacturer, Name,SoftwareElementID,SMBIOSBIOSVersion," & _
"SMBIOSMajorVersion,SMBIOSMinorVersion,Version"
QueryInstances "Win32_BIOS",strProperties,"None"

objFile.Close

'*****Subroutines and Functions*********
Sub QueryInstances(objClass,Properties,Conditions)
If Conditions = "None" Then
strSelect = "Select " & Properties & " From " & objClass
Else
strSelect = "Select " & Properties & " From " & objClass & _
" Where " & Conditions
End If
Set objClassName = _
objWMIService.ExecQuery _
(strSelect,,wbemFlagReturnImmediately + wbemFlagForwardOnly)
intCounter = 0
' Can use the following to determine the # of items in the
sWbemObjectSet but
' it's processor intensive and it means that you can't use a
semi-synchronous
' call because the count property doesn't work with
wbemFlagForwardOnly.
' WScript.Echo "# of items in collection: " & objClassName.Count
For Each objComponent in objClassName
If intCounter = 0 Then
objFile.WriteLine(HR)
objFile.WriteLine(Mid(objClass,7) & ":")
End If
For Each objProperty in objComponent.Properties_
'Start by verifying that there's a value in the property.
'If not, it isn't necessary to perform the evaluation in this
loop.
If ISNull(objProperty.Value) Then
objFile.WriteLine(objProperty.Name & ": Not available")
Else
If objProperty.CIMType <> wbemCimtypeUint32 And _
objProperty.CIMType <> wbemCimtypeUint64 And _
objProperty.CIMType <> wbemCimtypeSint64 Then
objFile.WriteLine(objProperty.Name & ": " & _
objProperty.Value & " " & _
GetUnits(objClass,objProperty.Name))
Else
strUnits = GetUnits(objClass,objProperty.Name)
intValue = _
SizeFormat(objProperty.Name,objProperty.Value,strUnits)
objFile.WriteLine(objProperty.Name & ": " & intValue)
End If
End If
intCounter = intCounter + 1
Next
If intCounter > 1 Then objFile.WriteLine(HR)
Next
objFile.WriteLine(HR)
objFile.WriteLine()
End Sub

Function GetUnits(ClassName,ClassProperty)
Set objSchemaClass = objWMIService.Get(ClassName)
For Each objClassProperty in objSchemaClass.Properties_
If objClassProperty.Name = ClassProperty Then
For Each objQualifier in objClassProperty.Qualifiers_
If LCase(objQualifier.Name) = "units" Then
GetUnits = LCase(objQualifier.Value)
End If
Next
End If
Next
End Function

Function SizeFormat(PropertyName,RawValue,Units)
Select Case LCase(Units)
Case "bytes"
If int(RawValue/GB) >= 1 Then
SizeFormat = Round((RawValue/GB),1) & " gigabyte(s)"
ElseIf int(RawValue/MB) >= 1 Then
SizeFormat = int(RawValue/MB) & " megabyte(s)"
Else
SizeFormat = RawValue & " byte(s)"
End If
Case "kilobytes"
If int(RawValue/MB) >= 1 Then
SizeFormat = Round((RawValue/MB),1) & " gigabyte(s)"
ElseIf int(RawValue/KB) >= 1 Then
SizeFormat = int(RawValue/1024) & " megabyte(s)"
Else
SizeFormat = RawValue & " kilobyte(s)"
End If
Case Else
SizeFormat = RawValue & " " & Units
End Select
End Function

Re: use text file for strComputer in VBS script by Gerry

Gerry
Mon Oct 04 14:29:36 CDT 2004

Hi Brian,

> I am trying to scan my network using this script listed below to scan
> a list of servers from a text file.

This is what I use. It accepts the full path to a text file with a
computer name on each line. It has the added bonus of letting you
"comment out" computers you don't want, by beginning the line with a
semi-colon. It won't crash if the file contains blank lines. Once you
get the array, you can just iterate it and do what you like to each
computer.

I've since moved on from this though, and now get my computer lists
direct from Active Directory.

function _getComputers(strFileSpec) {
// Accepts name of text file containing list (full path)
// Returns an array of NetBIOS computer names
// Skips blank lines and lines begenning with semicolon

var kForReading = 1;
var kForWriting = 2;
var kTristateUseDefault = -2; // ASCII on most systems

var re = /^;|^\s*$/;
var strLine;

var fso = new ActiveXObject("Scripting.FileSystemObject");

var arrCmpNames = new Array();
var f = fso.GetFile(strFileSpec);
var ts = f.OpenAsTextStream(kForReading, kTristateUseDefault);
while (!ts.atEndOfstream) {
strLine = ts.ReadLine();
if(!strLine.match(re)) {
arrCmpNames.push(strLine);
}
}
ts.Close();
return arrCmpNames;
}

--
Gerry Hickman (London UK)

Re: use text file for strComputer in VBS script by Mike

Mike
Mon Oct 04 17:22:35 CDT 2004

Yet another one;

' Specify the text file of computerNames.
strFilePath = "c:\MyFolder\NewComputers.txt"

' Open the file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFilePath, 1)

' Read each line of the file and set strComputerName.
Do Until objFile.AtEndOfStream
strComputerName = Trim(objFile.ReadLine)
If strComputerName <> "" Then
On Error Resume Next
Err.Clear
' Specify the actions to be taken here

--


---------------------------------------------------------------------
"Are you still wasting your time with spam?...
There is a solution!"

Protected by GIANT Company's Spam Inspector
The most powerful anti-spam software available.
http://mail.spaminspector.com


"Gerry Hickman" <gerry666uk@yahoo.co.uk> wrote in message
news:OMa5KhkqEHA.1644@tk2msftngp13.phx.gbl...
> Hi Brian,
>
>> I am trying to scan my network using this script listed below to scan
>> a list of servers from a text file.
>
> This is what I use. It accepts the full path to a text file with a
> computer name on each line. It has the added bonus of letting you "comment
> out" computers you don't want, by beginning the line with a semi-colon. It
> won't crash if the file contains blank lines. Once you get the array, you
> can just iterate it and do what you like to each computer.
>
> I've since moved on from this though, and now get my computer lists direct
> from Active Directory.
>
> function _getComputers(strFileSpec) {
> // Accepts name of text file containing list (full path)
> // Returns an array of NetBIOS computer names
> // Skips blank lines and lines begenning with semicolon
>
> var kForReading = 1;
> var kForWriting = 2;
> var kTristateUseDefault = -2; // ASCII on most systems
>
> var re = /^;|^\s*$/;
> var strLine;
>
> var fso = new ActiveXObject("Scripting.FileSystemObject");
>
> var arrCmpNames = new Array();
> var f = fso.GetFile(strFileSpec);
> var ts = f.OpenAsTextStream(kForReading, kTristateUseDefault);
> while (!ts.atEndOfstream) {
> strLine = ts.ReadLine();
> if(!strLine.match(re)) {
> arrCmpNames.push(strLine);
> }
> }
> ts.Close();
> return arrCmpNames;
> }
>
> --
> Gerry Hickman (London UK)



Re: use text file for strComputer in VBS script by brian

brian
Mon Oct 04 22:12:58 CDT 2004

"Mike" <mikef2691@comcast.net> wrote in message news:<#scMnCmqEHA.1960@TK2MSFTNGP10.phx.gbl>...
> Yet another one;
>
> ' Specify the text file of computerNames.
> strFilePath = "c:\MyFolder\NewComputers.txt"
>
> ' Open the file for read access.
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile(strFilePath, 1)
>
> ' Read each line of the file and set strComputerName.
> Do Until objFile.AtEndOfStream
> strComputerName = Trim(objFile.ReadLine)
> If strComputerName <> "" Then
> On Error Resume Next
> Err.Clear
> ' Specify the actions to be taken here
>
> --
>
>
> ---------------------------------------------------------------------
> "Are you still wasting your time with spam?...
> There is a solution!"
>
> Protected by GIANT Company's Spam Inspector
> The most powerful anti-spam software available.
> http://mail.spaminspector.com
>
>
> "Gerry Hickman" <gerry666uk@yahoo.co.uk> wrote in message
> news:OMa5KhkqEHA.1644@tk2msftngp13.phx.gbl...
> > Hi Brian,
> >
> >> I am trying to scan my network using this script listed below to scan
> >> a list of servers from a text file.
> >
> > This is what I use. It accepts the full path to a text file with a
> > computer name on each line. It has the added bonus of letting you "comment
> > out" computers you don't want, by beginning the line with a semi-colon. It
> > won't crash if the file contains blank lines. Once you get the array, you
> > can just iterate it and do what you like to each computer.
> >
> > I've since moved on from this though, and now get my computer lists direct
> > from Active Directory.
> >
> > function _getComputers(strFileSpec) {
> > // Accepts name of text file containing list (full path)
> > // Returns an array of NetBIOS computer names
> > // Skips blank lines and lines begenning with semicolon
> >
> > var kForReading = 1;
> > var kForWriting = 2;
> > var kTristateUseDefault = -2; // ASCII on most systems
> >
> > var re = /^;|^\s*$/;
> > var strLine;
> >
> > var fso = new ActiveXObject("Scripting.FileSystemObject");
> >
> > var arrCmpNames = new Array();
> > var f = fso.GetFile(strFileSpec);
> > var ts = f.OpenAsTextStream(kForReading, kTristateUseDefault);
> > while (!ts.atEndOfstream) {
> > strLine = ts.ReadLine();
> > if(!strLine.match(re)) {
> > arrCmpNames.push(strLine);
> > }
> > }
> > ts.Close();
> > return arrCmpNames;
> > }
> >
> > --
> > Gerry Hickman (London UK)



Here is the script i have now but seems to die at line 150. I can't
figure out why it dies when running the Subroutines and Functions.
Any other suggestions would be greatly apprciated.

'On Error Resume Next directive is specified so that users
'are not bothered by potential operational errors with the script.
'On Error Resume Next
'Using both of these flags of the WbemFlagEnum enumeration
'makes a semisynchronous WMI call. See "Making a Semisynchronous Call"
'in the WMI SDK for more information.
Const wbemFlagReturnImmediately = 16
Const wbemFlagForwardOnly = 32
'WbemCimtypeEnum Enumerations used in the script
Const wbemCimtypeUint32 = 19
Const wbemCimtypeSint64 = 20
Const wbemCimtypeUint64 = 21
'Formatting and number conversion constants
Const HR = "----"
Const KB = 1024
Const MB = 1048576
Const GB = 1073741824

'Change this to the UNC path where inventory files should be created
'Anyone running this script must have read and write access to the
'path.
strInvFilePath = "C:\hw\"

' Specify the text file of computerNames.
strFilePath = "c:\servers.txt"

' Open the file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFilePath, 1)

' Read each line of the file and set strComputerName.
Do Until objFile.AtEndOfStream
strComputerName = Trim(objFile.ReadLine)
If strComputerName <> "" Then
On Error Resume Next
Err.Clear


'Connect to WMI
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")

'Determine the OS because not all classes listed here are supported
'on all versions of the Windows operating systems
strProperties = "CreationClassName,Version,CSName,Caption"
Set objOS = objWMIService.ExecQuery _
("SELECT " & strProperties & " FROM Win32_OperatingSystem",_
,wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each Setting in objOS
strCreationClass = Setting.CreationClassName
intVersion = Setting.Version
strCSName = Setting.CSName
strCaption = Setting.Caption
Next

'Check for a file named after the computer. If it doesn't
'exist, then create a file that contains the computer's
'hardware inventory.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFileName = "HrdWrInv_" & strCSName & ".txt"
strFullName = objFSO.BuildPath(strInvFilePath, strFileName)
If (objFSO.FileExists(strFullName)) Then WScript.Quit
Set objFile = objFSO.CreateTextFile(strFullName)
'Write the Operating System name and version but nothing more.
'The goal is to collect hardware inventory, not software inventory
'and configuration information.
objFile.WriteLine("OSInformation:")
objFile.WriteLine("CreationClassName: " & strCreationClass)
objFile.WriteLine("ComputerName: " & strCSName)
objFile.WriteLine("Caption: " & strCaption)
objFile.WriteLine("Version: " & intVersion)

'The name property is automatically returned (because it's a key
value), so
'it's not absolutely necessary to specify it in strProperties
strProperties = _
"CreationClassName,Manufacturer,Model,Name,NumberofProcessors," & _
"SystemType,TotalPhysicalMemory"
QueryInstances "Win32_ComputerSystem",strProperties,"None"
'Page file information.
strProperties = _
"Name,MaximumSize"
QueryInstances "Win32_PageFileSetting",strProperties,"None"
'Physical memory information.
'Note, total memory is aggregated and listed with win32_computersystem
so there's
'no need to query the memory classes, such as
Win32_PhysicalMemoryArray or
'Win32_PhysicalMemory. However, if you need to find out how much
memory
'a computer will hold, it's useful to query Win32_PhysicalMemoryArray
as
'shown
strProperties = _
"MaxCapacity,CreationClassName"
QueryInstances "Win32_PhysicalMemoryArray",strProperties,"None"
'SCSI Disk controller information
strProperties = _
"Name,Manufacturer,Description,CreationClassName"
QueryInstances "Win32_SCSIController",strProperties,"None"
'IDE Disk controller information
strProperties = _
"Name,Manufacturer,Description,CreationClassName"
QueryInstances "Win32_IDEController",strProperties,"None"
'Phyiscal Media information
'Note, this class is only in XP (ver5) and the Windows
'Server 2003 family (ver5).
'Win98SE reports a version number of 4 (4.10.2222)
If Mid(intVersion,1,3) >= 5.1 Then
strProperties = _
"SerialNumber,CreationClassName"
QueryInstances "Win32_PhysicalMedia",strProperties,"None"
End If
'Logical Disk information
strProperties = _
"DriveType,Description,DeviceID,CreationClassName"
QueryInstances "Win32_LogicalDisk",strProperties,_
"DriveType!=3 AND DriveType !=4"
'Disk drive information
strProperties = _
"Caption,Description,DeviceID,InterfaceType," & _
"Manufacturer,MediaType,Model,Partitions,Size,CreationClassName"
QueryInstances "Win32_DiskDrive",strProperties,"None"
'Processor information
strProperties = _
"Manufacturer,MaxClockSpeed,ExtClock,ProcessorType," & _
"Revision,Version,CreationClassName"
QueryInstances "Win32_Processor",strProperties,"None"
'NIC information
strProperties = _
"Manufacturer,MACAddress,ProductName,AdapterType,CreationClassName"
QueryInstances "Win32_NetworkAdapter",strProperties,_
"AdapterType='Ethernet 802.3' AND ProductName !='Packet Scheduler
Miniport'"
'Monitor information
strProperties = _
"Description,MonitorType,CreationClassName"
QueryInstances "Win32_DesktopMonitor",strProperties,"None"
'Video adapter information
strProperties = _
"Name,MaxRefreshRate,AdapterRAM,CreationClassName"
QueryInstances "Win32_VideoController",strProperties,"None"
'Motherboard information
strProperties = _
"Description,Manufacturer,Product,CreationClassName"
QueryInstances "Win32_BaseBoard",strProperties,"None"
'BIOS information
strProperties = _
"Manufacturer, Name,SoftwareElementID,SMBIOSBIOSVersion," & _
"SMBIOSMajorVersion,SMBIOSMinorVersion,Version"
QueryInstances "Win32_BIOS",strProperties,"None"

objFile.Close

'*****Subroutines and Functions*********
Sub QueryInstances(objClass,Properties,Conditions)
If Conditions = "None" Then
strSelect = "Select " & Properties & " From " & objClass
Else
strSelect = "Select " & Properties & " From " & objClass & _
" Where " & Conditions
End If
Set objClassName = _
objWMIService.ExecQuery _
(strSelect,,wbemFlagReturnImmediately + wbemFlagForwardOnly)
intCounter = 0
' Can use the following to determine the # of items in the
sWbemObjectSet but
' it's processor intensive and it means that you can't use a
semi-synchronous
' call because the count property doesn't work with
wbemFlagForwardOnly.
' WScript.Echo "# of items in collection: " & objClassName.Count
For Each objComponent in objClassName
If intCounter = 0 Then
objFile.WriteLine(HR)
objFile.WriteLine(Mid(objClass,7) & ":")
End If
For Each objProperty in objComponent.Properties_
'Start by verifying that there's a value in the property.
'If not, it isn't necessary to perform the evaluation in this
loop.
If ISNull(objProperty.Value) Then
objFile.WriteLine(objProperty.Name & ": Not available")
Else
If objProperty.CIMType <> wbemCimtypeUint32 And _
objProperty.CIMType <> wbemCimtypeUint64 And _
objProperty.CIMType <> wbemCimtypeSint64 Then
objFile.WriteLine(objProperty.Name & ": " & _
objProperty.Value & " " & _
GetUnits(objClass,objProperty.Name))
Else
strUnits = GetUnits(objClass,objProperty.Name)
intValue = _
SizeFormat(objProperty.Name,objProperty.Value,strUnits)
objFile.WriteLine(objProperty.Name & ": " & intValue)
End If
End If
intCounter = intCounter + 1
Next
If intCounter > 1 Then objFile.WriteLine(HR)
Next
objFile.WriteLine(HR)
objFile.WriteLine()
End Sub

Function GetUnits(ClassName,ClassProperty)
Set objSchemaClass = objWMIService.Get(ClassName)
For Each objClassProperty in objSchemaClass.Properties_
If objClassProperty.Name = ClassProperty Then
For Each objQualifier in objClassProperty.Qualifiers_
If LCase(objQualifier.Name) = "units" Then
GetUnits = LCase(objQualifier.Value)
End If
Next
End If
Next
End Function

Function SizeFormat(PropertyName,RawValue,Units)
Select Case LCase(Units)
Case "bytes"
If int(RawValue/GB) >= 1 Then
SizeFormat = Round((RawValue/GB),1) & " gigabyte(s)"
ElseIf int(RawValue/MB) >= 1 Then
SizeFormat = int(RawValue/MB) & " megabyte(s)"
Else
SizeFormat = RawValue & " byte(s)"
End If
Case "kilobytes"
If int(RawValue/MB) >= 1 Then
SizeFormat = Round((RawValue/MB),1) & " gigabyte(s)"
ElseIf int(RawValue/KB) >= 1 Then
SizeFormat = int(RawValue/1024) & " megabyte(s)"
Else
SizeFormat = RawValue & " kilobyte(s)"
End If
Case Else
SizeFormat = RawValue & " " & Units
End Select
End Function



This is the line that the script dies at:

Sub QueryInstances(objClass,Properties,Conditions)

Thanks

Re: use text file for strComputer in VBS script by MFelkins

MFelkins
Tue Oct 05 10:11:05 CDT 2004

In this piece of code, try this;

' Specify the text file of computerNames.
strFilePath = "c:\servers.txt"

' Open the file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFilePath, 1)

' Read each line of the file and set strComputer.
Do Until objFile.AtEndOfStream
strComputer = Trim(objFile.ReadLine)
If strComputer<> "" Then
On Error Resume Next
Err.Clear
End if
Loop

You want to call strComputer here, not strComputerName. We need to do the
End If and then Loop the DO While. I am having problems now with this as it
skipps all the way down to the last line of my imput file. I will work with
it some more.

Mike



"Brian" wrote:

> "Mike" <mikef2691@comcast.net> wrote in message news:<#scMnCmqEHA.1960@TK2MSFTNGP10.phx.gbl>...
> > Yet another one;
> >
> > ' Specify the text file of computerNames.
> > strFilePath = "c:\MyFolder\NewComputers.txt"
> >
> > ' Open the file for read access.
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > Set objFile = objFSO.OpenTextFile(strFilePath, 1)
> >
> > ' Read each line of the file and set strComputerName.
> > Do Until objFile.AtEndOfStream
> > strComputerName = Trim(objFile.ReadLine)
> > If strComputerName <> "" Then
> > On Error Resume Next
> > Err.Clear
> > ' Specify the actions to be taken here
> >
> > --
> >
> >
> > ---------------------------------------------------------------------
> > "Are you still wasting your time with spam?...
> > There is a solution!"
> >
> > Protected by GIANT Company's Spam Inspector
> > The most powerful anti-spam software available.
> > http://mail.spaminspector.com
> >
> >
> > "Gerry Hickman" <gerry666uk@yahoo.co.uk> wrote in message
> > news:OMa5KhkqEHA.1644@tk2msftngp13.phx.gbl...
> > > Hi Brian,
> > >
> > >> I am trying to scan my network using this script listed below to scan
> > >> a list of servers from a text file.
> > >
> > > This is what I use. It accepts the full path to a text file with a
> > > computer name on each line. It has the added bonus of letting you "comment
> > > out" computers you don't want, by beginning the line with a semi-colon. It
> > > won't crash if the file contains blank lines. Once you get the array, you
> > > can just iterate it and do what you like to each computer.
> > >
> > > I've since moved on from this though, and now get my computer lists direct
> > > from Active Directory.
> > >
> > > function _getComputers(strFileSpec) {
> > > // Accepts name of text file containing list (full path)
> > > // Returns an array of NetBIOS computer names
> > > // Skips blank lines and lines begenning with semicolon
> > >
> > > var kForReading = 1;
> > > var kForWriting = 2;
> > > var kTristateUseDefault = -2; // ASCII on most systems
> > >
> > > var re = /^;|^\s*$/;
> > > var strLine;
> > >
> > > var fso = new ActiveXObject("Scripting.FileSystemObject");
> > >
> > > var arrCmpNames = new Array();
> > > var f = fso.GetFile(strFileSpec);
> > > var ts = f.OpenAsTextStream(kForReading, kTristateUseDefault);
> > > while (!ts.atEndOfstream) {
> > > strLine = ts.ReadLine();
> > > if(!strLine.match(re)) {
> > > arrCmpNames.push(strLine);
> > > }
> > > }
> > > ts.Close();
> > > return arrCmpNames;
> > > }
> > >
> > > --
> > > Gerry Hickman (London UK)
>
>
>
> Here is the script i have now but seems to die at line 150. I can't
> figure out why it dies when running the Subroutines and Functions.
> Any other suggestions would be greatly apprciated.
>
> 'On Error Resume Next directive is specified so that users
> 'are not bothered by potential operational errors with the script.
> 'On Error Resume Next
> 'Using both of these flags of the WbemFlagEnum enumeration
> 'makes a semisynchronous WMI call. See "Making a Semisynchronous Call"
> 'in the WMI SDK for more information.
> Const wbemFlagReturnImmediately = 16
> Const wbemFlagForwardOnly = 32
> 'WbemCimtypeEnum Enumerations used in the script
> Const wbemCimtypeUint32 = 19
> Const wbemCimtypeSint64 = 20
> Const wbemCimtypeUint64 = 21
> 'Formatting and number conversion constants
> Const HR = "----"
> Const KB = 1024
> Const MB = 1048576
> Const GB = 1073741824
>
> 'Change this to the UNC path where inventory files should be created
> 'Anyone running this script must have read and write access to the
> 'path.
> strInvFilePath = "C:\hw\"
>
> ' Specify the text file of computerNames.
> strFilePath = "c:\servers.txt"
>
> ' Open the file for read access.
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile(strFilePath, 1)
>
> ' Read each line of the file and set strComputerName.
> Do Until objFile.AtEndOfStream
> strComputerName = Trim(objFile.ReadLine)
> If strComputerName <> "" Then
> On Error Resume Next
> Err.Clear
>
>
> 'Connect to WMI
> Set objWMIService = GetObject("winmgmts:\\" & strComputer &
> "\root\cimv2")
>
> 'Determine the OS because not all classes listed here are supported
> 'on all versions of the Windows operating systems
> strProperties = "CreationClassName,Version,CSName,Caption"
> Set objOS = objWMIService.ExecQuery _
> ("SELECT " & strProperties & " FROM Win32_OperatingSystem",_
> ,wbemFlagReturnImmediately + wbemFlagForwardOnly)
>
> For Each Setting in objOS
> strCreationClass = Setting.CreationClassName
> intVersion = Setting.Version
> strCSName = Setting.CSName
> strCaption = Setting.Caption
> Next
>
> 'Check for a file named after the computer. If it doesn't
> 'exist, then create a file that contains the computer's
> 'hardware inventory.
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> strFileName = "HrdWrInv_" & strCSName & ".txt"
> strFullName = objFSO.BuildPath(strInvFilePath, strFileName)
> If (objFSO.FileExists(strFullName)) Then WScript.Quit
> Set objFile = objFSO.CreateTextFile(strFullName)
> 'Write the Operating System name and version but nothing more.
> 'The goal is to collect hardware inventory, not software inventory
> 'and configuration information.
> objFile.WriteLine("OSInformation:")
> objFile.WriteLine("CreationClassName: " & strCreationClass)
> objFile.WriteLine("ComputerName: " & strCSName)
> objFile.WriteLine("Caption: " & strCaption)
> objFile.WriteLine("Version: " & intVersion)
>
> 'The name property is automatically returned (because it's a key
> value), so
> 'it's not absolutely necessary to specify it in strProperties
> strProperties = _
> "CreationClassName,Manufacturer,Model,Name,NumberofProcessors," & _
> "SystemType,TotalPhysicalMemory"
> QueryInstances "Win32_ComputerSystem",strProperties,"None"
> 'Page file information.
> strProperties = _
> "Name,MaximumSize"
> QueryInstances "Win32_PageFileSetting",strProperties,"None"
> 'Physical memory information.
> 'Note, total memory is aggregated and listed with win32_computersystem
> so there's
> 'no need to query the memory classes, such as
> Win32_PhysicalMemoryArray or
> 'Win32_PhysicalMemory. However, if you need to find out how much
> memory
> 'a computer will hold, it's useful to query Win32_PhysicalMemoryArray
> as
> 'shown
> strProperties = _
> "MaxCapacity,CreationClassName"
> QueryInstances "Win32_PhysicalMemoryArray",strProperties,"None"
> 'SCSI Disk controller information
> strProperties = _
> "Name,Manufacturer,Description,CreationClassName"
> QueryInstances "Win32_SCSIController",strProperties,"None"
> 'IDE Disk controller information
> strProperties = _
> "Name,Manufacturer,Description,CreationClassName"
> QueryInstances "Win32_IDEController",strProperties,"None"
> 'Phyiscal Media information
> 'Note, this class is only in XP (ver5) and the Windows
> 'Server 2003 family (ver5).
> 'Win98SE reports a version number of 4 (4.10.2222)
> If Mid(intVersion,1,3) >= 5.1 Then
> strProperties = _
> "SerialNumber,CreationClassName"
> QueryInstances "Win32_PhysicalMedia",strProperties,"None"
> End If
> 'Logical Disk information
> strProperties = _
> "DriveType,Description,DeviceID,CreationClassName"
> QueryInstances "Win32_LogicalDisk",strProperties,_
> "DriveType!=3 AND DriveType !=4"
> 'Disk drive information
> strProperties = _
> "Caption,Description,DeviceID,InterfaceType," & _
> "Manufacturer,MediaType,Model,Partitions,Size,CreationClassName"
> QueryInstances "Win32_DiskDrive",strProperties,"None"
> 'Processor information
> strProperties = _
> "Manufacturer,MaxClockSpeed,ExtClock,ProcessorType," & _
> "Revision,Version,CreationClassName"
> QueryInstances "Win32_Processor",strProperties,"None"
> 'NIC information
> strProperties = _
> "Manufacturer,MACAddress,ProductName,AdapterType,CreationClassName"
> QueryInstances "Win32_NetworkAdapter",strProperties,_
> "AdapterType='Ethernet 802.3' AND ProductName !='Packet Scheduler
> Miniport'"
> 'Monitor information
> strProperties = _
> "Description,MonitorType,CreationClassName"
> QueryInstances "Win32_DesktopMonitor",strProperties,"None"
> 'Video adapter information
> strProperties = _
> "Name,MaxRefreshRate,AdapterRAM,CreationClassName"
> QueryInstances "Win32_VideoController",strProperties,"None"
> 'Motherboard information
> strProperties = _
> "Description,Manufacturer,Product,CreationClassName"
> QueryInstances "Win32_BaseBoard",strProperties,"None"
> 'BIOS information
> strProperties = _
> "Manufacturer, Name,SoftwareElementID,SMBIOSBIOSVersion," & _
> "SMBIOSMajorVersion,SMBIOSMinorVersion,Version"
> QueryInstances "Win32_BIOS",strProperties,"None"
>
> objFile.Close
>
> '*****Subroutines and Functions*********
> Sub QueryInstances(objClass,Properties,Conditions)
> If Conditions = "None" Then
> strSelect = "Select " & Properties & " From " & objClass
> Else
> strSelect = "Select " & Properties & " From " & objClass & _
> " Where " & Conditions
> End If
> Set objClassName = _
> objWMIService.ExecQuery _
> (strSelect,,wbemFlagReturnImmediately + wbemFlagForwardOnly)
> intCounter = 0
> ' Can use the following to determine the # of items in the
> sWbemObjectSet but
> ' it's processor intensive and it means that you can't use a
> semi-synchronous
> ' call because the count property doesn't work with
> wbemFlagForwardOnly.
> ' WScript.Echo "# of items in collection: " & objClassName.Count
> For Each objComponent in objClassName
> If intCounter = 0 Then
> objFile.WriteLine(HR)
> objFile.WriteLine(Mid(objClass,7) & ":")
> End If
> For Each objProperty in objComponent.Properties_
> 'Start by verifying that there's a value in the property.
> 'If not, it isn't necessary to perform the evaluation in this
> loop.
> If ISNull(objProperty.Value) Then
> objFile.WriteLine(objProperty.Name & ": Not available")
> Else
> If objProperty.CIMType <> wbemCimtypeUint32 And _
> objProperty.CIMType <> wbemCimtypeUint64 And _
> objProperty.CIMType <> wbemCimtypeSint64 Then
> objFile.WriteLine(objProperty.Name & ": " & _
> objProperty.Value & " " & _
> GetUnits(objClass,objProperty.Name))
> Else
> strUnits = GetUnits(objClass,objProperty.Name)
> intValue = _
> SizeFormat(objProperty.Name,objProperty.Value,strUnits)
> objFile.WriteLine(objProperty.Name & ": " & intValue)
> End If
> End If
> intCounter = intCounter + 1
> Next
> If intCounter > 1 Then objFile.WriteLine(HR)
> Next
> objFile.WriteLine(HR)
> objFile.WriteLine()
> End Sub
>
> Function GetUnits(ClassName,ClassProperty)
> Set objSchemaClass = objWMIService.Get(ClassName)
> For Each objClassProperty in objSchemaClass.Properties_
> If objClassProperty.Name = ClassProperty Then
> For Each objQualifier in objClassProperty.Qualifiers_
> If LCase(objQualifier.Name) = "units" Then
> GetUnits = LCase(objQualifier.Value)
> End If
> Next
> End If
> Next
> End Function
>
> Function SizeFormat(PropertyName,RawValue,Units)
> Select Case LCase(Units)
> Case "bytes"
> If int(RawValue/GB) >= 1 Then
> SizeFormat = Round((RawValue/GB),1) & " gigabyte(s)"
> ElseIf int(RawValue/MB) >= 1 Then
> SizeFormat = int(RawValue/MB) & " megabyte(s)"
> Else
> SizeFormat = RawValue & " byte(s)"
> End If
> Case "kilobytes"
> If int(RawValue/MB) >= 1 Then
> SizeFormat = Round((RawValue/MB),1) & " gigabyte(s)"
> ElseIf int(RawValue/KB) >= 1 Then
> SizeFormat = int(RawValue/1024) & " megabyte(s)"
> Else
> SizeFormat = RawValue & " kilobyte(s)"
> End If
> Case Else
> SizeFormat = RawValue & " " & Units
> End Select
> End Function
>
>
>
> This is the line that the script dies at:
>
> Sub QueryInstances(objClass,Properties,Conditions)
>
> Thanks
>

Re: use text file for strComputer in VBS script by Al

Al
Thu Oct 07 21:21:14 CDT 2004


"Brian" <brian@abgm.net> wrote in message
news:9abd6af0.0410041912.6701eea0@posting.google.com...
> "Mike" <mikef2691@comcast.net> wrote in message
news:<#scMnCmqEHA.1960@TK2MSFTNGP10.phx.gbl>...
> > Yet another one;

<snip>

> Here is the script i have now but seems to die at line 150. I can't
> figure out why it dies when running the Subroutines and Functions.
> Any other suggestions would be greatly apprciated.

Seems, madam! nay, it is; I know not "seems."

But, Shakespearean quotes aside, how do you know it is at line 150 when it
does what you interpret as seeming to die? Does it display an error message
with line number, perhaps? If so, what is the error message? If not, then
what precisely do you mean?

/Al



Re: use text file for strComputer in VBS script by MFelkins

MFelkins
Fri Oct 08 12:29:02 CDT 2004

If I preceed this line with LOOP the script works, but... It only reports on
the last server name in the list.

(151, 1) Microsoft VBScript compilation error: Syntax error


"Al Dunbar [MS-MVP]" wrote:

>
> "Brian" <brian@abgm.net> wrote in message
> news:9abd6af0.0410041912.6701eea0@posting.google.com...
> > "Mike" <mikef2691@comcast.net> wrote in message
> news:<#scMnCmqEHA.1960@TK2MSFTNGP10.phx.gbl>...
> > > Yet another one;
>
> <snip>
>
> > Here is the script i have now but seems to die at line 150. I can't
> > figure out why it dies when running the Subroutines and Functions.
> > Any other suggestions would be greatly apprciated.
>
> Seems, madam! nay, it is; I know not "seems."
>
> But, Shakespearean quotes aside, how do you know it is at line 150 when it
> does what you interpret as seeming to die? Does it display an error message
> with line number, perhaps? If so, what is the error message? If not, then
> what precisely do you mean?
>
> /Al
>
>
>

Re: use text file for strComputer in VBS script by Al

Al
Fri Oct 08 18:47:29 CDT 2004


"MFelkins" <MFelkins@discussions.microsoft.com> wrote in message
news:6DB79C10-BC70-49D3-90DC-B612DF34E976@microsoft.com...
> If I preceed this line with LOOP the script works, but... It only reports
on
> the last server name in the list.
>
> (151, 1) Microsoft VBScript compilation error: Syntax error

Sorry, this is getting too confusing. One post says the script dies at line
150, another says it is at the Sub
QueryInstances(objClass,Properties,Conditions) line, which is line 140 by my
count.

If you want help with the syntax error above, please post the offending
line.

/Al



> "Al Dunbar [MS-MVP]" wrote:
>
> >
> > "Brian" <brian@abgm.net> wrote in message
> > news:9abd6af0.0410041912.6701eea0@posting.google.com...
> > > "Mike" <mikef2691@comcast.net> wrote in message
> > news:<#scMnCmqEHA.1960@TK2MSFTNGP10.phx.gbl>...
> > > > Yet another one;
> >
> > <snip>
> >
> > > Here is the script i have now but seems to die at line 150. I can't
> > > figure out why it dies when running the Subroutines and Functions.
> > > Any other suggestions would be greatly apprciated.
> >
> > Seems, madam! nay, it is; I know not "seems."
> >
> > But, Shakespearean quotes aside, how do you know it is at line 150 when
it
> > does what you interpret as seeming to die? Does it display an error
message
> > with line number, perhaps? If so, what is the error message? If not,
then
> > what precisely do you mean?
> >
> > /Al
> >
> >
> >



Re: use text file for strComputer in VBS script by MFelkins

MFelkins
Tue Oct 12 17:03:02 CDT 2004

It dies rhigth here;

'*****Subroutines and Functions*********
Sub QueryInstances(objClass,Properties,Conditions)

Mike

"Al Dunbar [MS-MVP]" wrote:

>
> "MFelkins" <MFelkins@discussions.microsoft.com> wrote in message
> news:6DB79C10-BC70-49D3-90DC-B612DF34E976@microsoft.com...
> > If I preceed this line with LOOP the script works, but... It only reports
> on
> > the last server name in the list.
> >
> > (151, 1) Microsoft VBScript compilation error: Syntax error
>
> Sorry, this is getting too confusing. One post says the script dies at line
> 150, another says it is at the Sub
> QueryInstances(objClass,Properties,Conditions) line, which is line 140 by my
> count.
>
> If you want help with the syntax error above, please post the offending
> line.
>
> /Al
>
>
>
> > "Al Dunbar [MS-MVP]" wrote:
> >
> > >
> > > "Brian" <brian@abgm.net> wrote in message
> > > news:9abd6af0.0410041912.6701eea0@posting.google.com...
> > > > "Mike" <mikef2691@comcast.net> wrote in message
> > > news:<#scMnCmqEHA.1960@TK2MSFTNGP10.phx.gbl>...
> > > > > Yet another one;
> > >
> > > <snip>
> > >
> > > > Here is the script i have now but seems to die at line 150. I can't
> > > > figure out why it dies when running the Subroutines and Functions.
> > > > Any other suggestions would be greatly apprciated.
> > >
> > > Seems, madam! nay, it is; I know not "seems."
> > >
> > > But, Shakespearean quotes aside, how do you know it is at line 150 when
> it
> > > does what you interpret as seeming to die? Does it display an error
> message
> > > with line number, perhaps? If so, what is the error message? If not,
> then
> > > what precisely do you mean?
> > >
> > > /Al
> > >
> > >
> > >
>
>
>

Re: use text file for strComputer in VBS script by Al

Al
Tue Oct 12 17:50:32 CDT 2004


"MFelkins" <MFelkins@discussions.microsoft.com> wrote in message
news:949CD9EF-CCC8-4F90-BABB-A0388AB6F94C@microsoft.com...
> It dies rhigth here;
>
> '*****Subroutines and Functions*********
> Sub QueryInstances(objClass,Properties,Conditions)

Sigh... Like I said below (down at the bottom of this post) what, precisely,
do you mean by this?

If this is the line indicated by an error message, what is the error
message? I don't see anything wrong with the statement itself, so if it
throws a syntax error message of some sort, this must be caused by the
context in which it appears. If, for example, it appeared between another
SUB statement and the corresponding END SUB statement, that could be your
problem.

If this is NOT a line indicated by an error message, it could be that you
are not aware that the code within a SUB is only invoked if the SUB is
called, and not just because the SUB appears in the code.

There is a multitude of other possibilities that can only be determined by a
mind reader or if you would give more information.

/Al

> Mike
>
> "Al Dunbar [MS-MVP]" wrote:
>
> >
> > "MFelkins" <MFelkins@discussions.microsoft.com> wrote in message
> > news:6DB79C10-BC70-49D3-90DC-B612DF34E976@microsoft.com...
> > > If I preceed this line with LOOP the script works, but... It only
reports
> > on
> > > the last server name in the list.
> > >
> > > (151, 1) Microsoft VBScript compilation error: Syntax error
> >
> > Sorry, this is getting too confusing. One post says the script dies at
line
> > 150, another says it is at the Sub
> > QueryInstances(objClass,Properties,Conditions) line, which is line 140
by my
> > count.
> >
> > If you want help with the syntax error above, please post the offending
> > line.
> >
> > /Al
> >
> >
> >
> > > "Al Dunbar [MS-MVP]" wrote:
> > >
> > > >
> > > > "Brian" <brian@abgm.net> wrote in message
> > > > news:9abd6af0.0410041912.6701eea0@posting.google.com...
> > > > > "Mike" <mikef2691@comcast.net> wrote in message
> > > > news:<#scMnCmqEHA.1960@TK2MSFTNGP10.phx.gbl>...
> > > > > > Yet another one;
> > > >
> > > > <snip>
> > > >
> > > > > Here is the script i have now but seems to die at line 150. I
can't
> > > > > figure out why it dies when running the Subroutines and Functions.
> > > > > Any other suggestions would be greatly apprciated.
> > > >
> > > > Seems, madam! nay, it is; I know not "seems."
> > > >
> > > > But, Shakespearean quotes aside, how do you know it is at line 150
when
> > it
> > > > does what you interpret as seeming to die? Does it display an error
> > message
> > > > with line number, perhaps? If so, what is the error message? If not,
> > then
> > > > what precisely do you mean?
> > > >
> > > > /Al
> > > >
> > > >
> > > >
> >
> >
> >