<> wrote in message
news:f86e43c7-9edd-4d4c-9621-...
> Hi All,
>
> I have been working on a script to output the logged on users of a
> remote system. This is the base script that I got from Microsoft
> Script Center and it works fine:
>
> strComputer = "atl-ws-o1"
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root
> \cimv2")
>
> Set colComputer = objWMIService.ExecQuery _
> ("Select * from Win32_ComputerSystem")
>
> For Each objComputer in colComputer
> Wscript.Echo "Logged-on user: " & objComputer.UserName
> Next
>
> Then I change it slightly to be able to read from a list of computer
> names that is in a separate text file. It gives an error: Line:10,
> Char:5, Error: Type mismatch
>
> Const ForReading = 1
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile _
> ("c:\test\test2\scanlist.txt", ForReading)
>
> Do Until objTextFile.AtEndOfStream
> strNextline = objTextFile.readline
> strComputer = Split(strNextline , ",")
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root
> \cimv2")
>
> Set colComputer = objWMIService.ExecQuery _
> ("Select * from Win32_ComputerSystem")
>
> For Each objComputer in colComputer
> Wscript.Echo "Logged-on user: " & objComputer.UserName
> Next
> Loop
>
> Please let me know if you have any advise on this.
>
> Thank you.
As urkec noted, the Split function returns an array. If the file has one
NetBIOS name per line, use:
strComputer = objTextFile.ReadLine
If each line has comma delimited values, and the first value is the NetBIOS
name of the computer, use:
arrValues = Split(objTextFile.ReadLine, ",")
strComputer = arrValues(0)
If the computer NetBIOS name is the third value in the comma delimited line,
use:
arrValues = Split(objTextFile.ReadLine, ",")
strComputer = arrValues(2)
--
Richard Mueller
MVP Directory Services
Hilltop Lab -
http://www.rlmueller.net
--