Re: Input File for Script
- From: "Al Dunbar" <AlanNOSPAmDrub@xxxxxxxxxxx>
- Date: Fri, 16 Dec 2005 17:17:47 -0800
"Scott" <Scott@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:96EADDFE-6F54-4CE6-9277-16E39BEF07A4@xxxxxxxxxxxxxxxx
>I have found the below script online (Thanks Alex and Torgeir) that does
> everything I need to do when searching for members of the local
> administrators group. I would like to know if someone can tell me how to
> use
> an input file to populate the aComputers field. I have a file
> (computers.txt) that has all of the computers listed that I would like to
> search. How can I make this script use this standard text file to input
> the
> array of computers?
The seven lines below should do this for you, assuming that your text file
has one computer name per line with no extraneous characters or whitespace.
Alternatively, if these are members of an active directory domain, perhaps a
better approach would be to get the computer names from there.
> ' some array with computers
> aComputers = Array("computer1", "computer2")
const ForReading = 1
set fso = createobject("scripting.filesystemobject")
set fileob = fso.opentextfile("C:\computers.txt",forReading,true
filecontent = fileob.readall
fileob.close
set fileob = nothing
aComputers = split(filecontent,vbnewline)
/Al
> For Each sComputer In aComputers
> ' check if computer is online
> If IsConnectible(sComputer, 1, 750) Then
>
>
> ' suppress errors
> On Error Resume Next
>
>
> ' group name to list users from
> Set oGroupAdm = GetObject("WinNT://" & sComputer & "/Administrators")
> If Err.Number = 0 Then
> WScript.Echo "Administator members of computer: " & sComputer &
> vbCrLf
> ' loop through all member of the group
> For Each oAdmGrpUser In oGroupAdm.Members
> ' get the name
> sAdmGrpUser = oAdmGrpUser.Name
> ' no point in listing Administrator
> ' use lowercase letters in the names in the If test!
> If LCase(sAdmGrpUser) <> "administrator" Then
> WScript.Echo sAdmGrpUser
> End If
> Next
> Else
> WScript.Echo "Could not connect to computer: " & sComputer
> End If
> Else
> WScript.Echo sComputer & " is not online"
> End If
> Err.Clear
> Next
> On Error Goto 0
>
>
> 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
>
>
> If iPings = "" Then iPings = 2
> If iTO = "" Then iTO = 750
>
>
> Const OpenAsDefault = -2
> Const FailIfNotExist = 0
> Const ForReading = 1
>
>
> Set oShell = CreateObject("WScript.Shell")
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
> sTempFile = sTemp & "\runresult.tmp"
>
>
> oShell.Run "%comspec% /c ping -n " & iPings & " -w " & iTO _
> & " " & sHost & ">" & sTempFile, 0 , True
>
>
> Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
> FailIfNotExist, OpenAsDefault)
>
>
> sResults = fFile.ReadAll
> fFile.Close
> oFSO.DeleteFile(sTempFile)
>
>
> Select Case InStr(sResults,"TTL=")
> Case 0 IsConnectible = False
> Case Else IsConnectible = True
> End Select
> End Function
>
>
>
.
- Follow-Ups:
- Re: Input File for Script
- From: OldDog
- Re: Input File for Script
- References:
- Input File for Script
- From: Scott
- Input File for Script
- Prev by Date: Re: Win32Shutdown & Terminal Services
- Next by Date: wireless in XP
- Previous by thread: Input File for Script
- Next by thread: Re: Input File for Script
- Index(es):
Relevant Pages
|