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

Input from text file.

2 views
Skip to first unread message

Troy Mayfield

unread,
Aug 26, 2003, 3:17:12 PM8/26/03
to
Is there any way I can have strComputerName pull the
needed information from a text file?


strComputerName = InputBox ("enter computer name")

Robert Cohen

unread,
Aug 26, 2003, 3:27:11 PM8/26/03
to
you want it to pull from a line of text instead of the inputbox?

THis script will read a text file line by line and make each line the string
until the end of the text file.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\temp\2.txt", 1)
Do Until objFile.AtEndOfStream
strComputername = objFile.ReadLine
wscript.echo strCharacters
Loop

--
Robert Cohen
A legend in his own mind
--

"Troy Mayfield" <Tmay...@trillis.com> wrote in message
news:0ace01c36c06$a7098b50$a001...@phx.gbl...

Torgeir Bakken (MVP)

unread,
Aug 26, 2003, 3:36:46 PM8/26/03
to
Troy Mayfield wrote:

Hi

Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objShell = CreateObject("WScript.Shell")

' input file
strInFile = "C:\logs\computer.txt"

If Not objFSO.FileExists(strInFile) Then
WScript.Echo "Could not find the input file!"
End If

Set fInFile = objFSO.OpenTextFile(strInFile, ForReading, _
FailIfNotExist, OpenAsASCII)

arrContents = Split(fInFile.ReadAll, vbCrLf)
fInFile.Close

For n = 0 to UBound(arrContents)
strComputerName = Trim(arrContents(n))
If strComputerName <> "" Then
WScript.Echo strComputerName
End If
Next


--
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/scriptcenter


Troy Mayfield

unread,
Aug 26, 2003, 4:16:47 PM8/26/03
to
Torgier,

I attempted to make an addition to the script with tour
responce below, but the 5 subroutines underneath the new
entry didn't seem to run as they did before (error
= "invalid procedure call or arguement: 'GetObject'".

The purpose of this script is to poll a remote computer
for its serices and report what was found to an access
database. I just wanted the script to read the hostnames
from a text file and then proceed on through the
subroutines.

Any thoughts?

>.
>

Troy Mayfield

unread,
Aug 26, 2003, 4:21:19 PM8/26/03
to
here was the line it alluding to:

Set CompSysSet = GetObject(strWinMgt).ExecQuery("select *
from Win32_ComputerSystem")

error = "invalid procedure call or arangement: 'get
object'"

>.
>

Torgeir Bakken (MVP)

unread,
Aug 26, 2003, 5:02:46 PM8/26/03
to
Troy Mayfield wrote:

> here was the line it alluding to:
>
> Set CompSysSet = GetObject(strWinMgt).ExecQuery("select *
> from Win32_ComputerSystem")
>
> error = "invalid procedure call or arangement: 'get
> object'"

Hi

To little information I'm afraid (e.g. I need to see the build up of the
variable strWinMgt). Could you post your code?

Troy Mayfield

unread,
Aug 26, 2003, 5:24:56 PM8/26/03
to
Torgier,
This script is was actually built off servinv.vbs script
located at
http://www.serverwatch.com/tutorials/article.php/1475601.
Can you please show me how you can take -> strComputerName
= InputBox ("enter computer name") and change it around so
instead of having to manually enter the hostname, the
hostname will be fed from a text file? Your help is
honestly appreciated!

Thanks,

>.
>

Torgeir Bakken (MVP)

unread,
Aug 26, 2003, 6:00:13 PM8/26/03
to
Troy Mayfield wrote:

> Torgier,
> This script is was actually built off servinv.vbs script
> located at
> http://www.serverwatch.com/tutorials/article.php/1475601.
> Can you please show me how you can take -> strComputerName
> = InputBox ("enter computer name") and change it around so
> instead of having to manually enter the hostname, the
> hostname will be fed from a text file? Your help is
> honestly appreciated!

Hi

In the code below, consider changing

strWinMgt = "winmgmts://" & strComputerName &""

to
strWinMgt = "winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputerName & "\root\cimv2"

Here is the complete code after the Dims, before the Subs:


' Dims stop here

Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")

' input file
strInFile = "C:\logs\computer.txt"

If Not objFSO.FileExists(strInFile) Then
WScript.Echo "Could not find the input file!"
End If

Set fInFile = objFSO.OpenTextFile(strInFile, ForReading, _
FailIfNotExist, OpenAsASCII)

'
' Get the Computer Names to Collect Information For
'


arrContents = Split(fInFile.ReadAll, vbCrLf)
fInFile.Close

call subConnectionOpen

'
' Loop through computer names
'


For n = 0 to UBound(arrContents)
strComputerName = Trim(arrContents(n))
If strComputerName <> "" Then

strWinMgt = "winmgmts://" & strComputerName &""

'
' Write Computer Info to Database
'
call subWriteComputerInfo
call subWriteDiskInfo
call subWriteIPInfo

End If
Next


call subConnectionClose


wscript.echo "Finished Collection Information for the Systems."

' Subs starts here

Troy Mayfield

unread,
Aug 26, 2003, 7:16:37 PM8/26/03
to
I get the following error message -> 'the field is too
small to accept the ammount of data you attempted to add,
try inserting or pasting less dats' (there is only one
hostname in the .txt file).

Torgier,
Would you mind pasting your version of the script, with
the new editions?

>.
>

Torgeir Bakken (MVP)

unread,
Aug 26, 2003, 7:35:28 PM8/26/03
to
Troy Mayfield wrote:

> I get the following error message -> 'the field is too
> small to accept the ammount of data you attempted to add,
> try inserting or pasting less dats' (there is only one
> hostname in the .txt file).
>
> Torgier,
> Would you mind pasting your version of the script, with
> the new editions?

That would be an error in the database writing to the mdb file I think. I did
not test that part of the code, and I have not enough knowledge of handling MS
Jet.OLEDB issues to be able to help you on this am I afraid.

Troy Mayfield

unread,
Aug 26, 2003, 8:31:16 PM8/26/03
to
Thats fine with me, I'll take it from here, thanks for the
input. You are a great asset to this group!

>.
>

Torgeir Bakken (MVP)

unread,
Aug 26, 2003, 8:41:18 PM8/26/03
to
Troy Mayfield wrote:

> Thats fine with me, I'll take it from here, thanks for the
> input. You are a great asset to this group!

Thanks :-)

0 new messages