$aTargets = FileIO('c:\scripts\hosts.txt', 'R')
For Each $Host in $aTargets
; run code to query each $Host value
If Ping($Host)
$HostPath = '\\' + $Host + '\C$\users'
'Processing ' $HostPath ? ; for debugging or status reporting
; run any necessary command using $HostPath to reference the target path
$logFile = @ScriptDir+"\Profile Sizes.ini"
$profiles = DirList($HostPath, 3)
For Each $profile in $profiles
If Right($profile, 1) = "\"
$profilename = Split($profile, "\")
$profilename = $profilename[UBound($profilename)-1]
$nul = WriteProfileString($logfile, $Host+"\"+$profilename, "Desktop", fnGetFolderProp($profile+"Desktop","Size"))
$nul = WriteProfileString($logfile, $Host+"\"+$profilename, "Documents", fnGetFolderProp($profile+"My Documents","Size"))
Endif
Next
Endif
Next
Function fnGetFolderProp($sFldr,$sProp)
Dim $objFSO, $objFldr, $nul
$objFSO = CreateObject("Scripting.FileSystemObject")
If Not VarType($objFSO)=9 Exit 1 EndIf
$objFldr = $objFSO.GetFolder($sFldr)
If Not VarType($objFldr)=9 Exit 3 EndIf
$nul=Execute("$$fnGetFolderProp = $$objFldr."+$sProp)
If VarType($fnGetFolderProp)=0 Exit 87 EndIf
EndFunction
Function dirlist($dirname, optional $options)
dim $filename, $counter, $filepath, $mask
dim $list, $sublist, $subcounter
$counter=-1
$dirname=trim($dirname)
if $dirname=''
$dirname=@CURDIR
endif
if right($dirname,1)='\'
$dirname=left($dirname,len($dirname)-1)
endif
if getfileattr($dirname) & 16
$mask='*.*'
else
$mask=substr($dirname,instrrev($dirname,'\')+1)
$dirname=left($dirname,len($dirname)-len($mask)-1)
endif
redim $list[10]
$filename=dir($dirname+'\'+$mask)
while $filename<>'' and @ERROR=0
if $filename<>'.' and $filename<>'..'
select
case (getfileattr($dirname+'\'+$filename) & 16)
if $options & 1
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'
else
$list[$counter]=$filename+'\'
endif
endif
if ($options & 4)
$sublist=dirlist($dirname+'\'+$filename+'\'+$mask,$options)
if ubound($sublist)+1
redim preserve $list[ubound($list)+ubound($sublist)+1]
for $subcounter=0 to ubound($sublist)
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
else
$list[$counter]=$filename+'\'+$sublist[$subcounter]
endif
next
endif
endif
case ($options & 2)
$counter=$counter+1
$list[$counter]=$dirname+'\'+$filename
case 1
$counter=$counter+1
$list[$counter]=$filename
endselect
if $counter mod 10
redim preserve $list[$counter+10]
endif
endif
$filename = dir('')
loop
if $counter+1
redim preserve $list[$counter]
else
$list=''
endif
if $mask<>'*.*' and ($options & 4)
$filename=dir($dirname+'\*.*')
while $filename<>'' and @ERROR=0
if $filename<>'.' and $filename<>'..'
if (getfileattr($dirname+'\'+$filename) & 16)
$sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4)
if ubound($sublist)+1
redim preserve $list[ubound($list)+ubound($sublist)+1]
for $subcounter=0 to ubound($sublist)
$counter=$counter+1
if $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
else
$list[$counter]=$filename+'\'+$sublist[$subcounter]
endif
next
endif
endif
endif
$filename = dir('')
loop
endif
if $counter+1
redim preserve $list[$counter]
else
$list=''
endif
$dirlist=$list
endfunction
Function FileIO($_File, $_Mode, OPTIONAL $_aData, OPTIONAL $_Opts)
Dim $_ ; temp var
Dim $_I ; index pointer
Dim $_Fp ; file pointer
Dim $_Fm ; file I/O mode
Dim $_Term ; line terminator
Dim $_NoNul ; Null line suppression flag
Dim $_FTerm ; final line term
Dim $_Prog ; Progress indicator flag
$FileIO = 0 ; return fail by default
; set the process options
$_Term = IIf($_Opts & 1, Chr(10), @CRLF)
$_NoNul = IIf($_Opts & 2, 1, 0)
$_FTerm = IIf($_Opts & 4, '', $_Term)
$_Prog = IIf($_Opts & 8, 1, 0)
; validate the mode & set the I/O mode
$_Mode = Left($_Mode, 1)
Select
Case $_Mode = 'R' ; read
$_Fm = 2
Case $_Mode = 'W' ; write/create
If VarType($_aData) < 8192
Exit 87 ; exit with error if Write/Create mode and no data
EndIf
$_Fm = 5
If Exist($_File) ; remove any existing file if not in Append mode
Del $_File
EndIf
Case $_Mode = 'A' ; append
If VarType($_aData) < 8192
Exit 87 ; exit with error if Write/Append mode and no data
EndIf
$_Fm = 5
Case 1 ; invalid mode
Exit 87
EndSelect
; locate an available file handle
$_Fp = FreeFileHandle
If Not $_Fp
Exit 1
EndIf
; Open the file in the defined input or output mode - exit if the open fails
$_ = Open($_Fp, $_File, $_Fm)
If @ERROR Exit @ERROR EndIf
If $_Fm = 2 ; read file
ReDim $_aData[499] ; start w/ 500 lines
$_I = -1
$_ = ReadLine($_Fp)
While Not @ERROR
$_I = $_I + 1
$_aData[$_I] = $_
If $_I > 1 And $_I Mod 499 = 0
ReDim Preserve $_aData[$_I + 500]
If $_Prog '.' EndIf ; progress marker
EndIf
$_ = ReadLine($_Fp)
Loop
$_ = Close($_Fp)
ReDim Preserve $_aData[$_I]
If $_Prog '. ' EndIf
$FileIO = $_aData
Exit 0
Else ; write file
For $_I = 0 to UBound($_aData) - 1
If $_NoNul
If $_aData[$_I] ; write if not null
$_ = WriteLine($_FP, $_aData[$_I] + $_Term)
EndIf
Else ; write always
$_ = WriteLine($_FP, $_aData[$_I] + $_Term)
EndIf
If $_I > 1 And $_I Mod 499 = 0 And $_Prog '.' EndIf
Next
; write last line
If $_NoNul
If $_aData[$_I] ; write if not null
$_ = WriteLine($_FP, $_aData[$_I] + $_FTerm)
EndIf
Else ; write always
$_ = WriteLine($_FP, $_aData[$_I] + $_FTerm)
EndIf
$_ = Close($_Fp)
$FileIO = 1 ; show a completed write
If $_Prog '. ' EndIf
Exit 0
EndIf
EndFunction
Function Ping($_Host, OPTIONAL $_Flag, OPTIONAL $_Wait)
Dim $_oExec ; WSH Object
Dim $_Tries ; # of times to ping
Dim $_Timeout ; Ping timeout value
Dim $_Response ; Response Flag
Dim $_Line ; Line returned from command string
Dim $_Cmd ; first part of command string
Dim $_Count ; current ping count
$_Flag = Val($_Flag) ; determine what to do
$_Wait = Val($_Wait) ;
$_Tries = 1 ; one ping
$_Timeout = 1000 ; 1 second timeout
; set timeout if Wait is non-zero
If $_Wait > 0
$_Timeout = $_Wait
EndIf
If $_FLAG > 0 ; Multiple pings - return on first reply
$_Tries = $_FLAG
EndIf
; Ping the host $_Tries times, but only until a response is received
$_Count = 0
; search for reply from host during PING
$_Cmd = '%COMSPEC% /c ping.exe -4 -n 1 -w ' + $_Timeout + ' ' + $_Host
If $_Flag < 0
$_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Pinging"'
Else
$_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Reply" | %SystemRoot%\System32\Find "TTL="'
EndIf
Do
$_oExec = CreateObject("WScript.Shell").Exec($_Cmd)
If Not VarType($_oExec)=9 $Ping = 'WScript.Shell Exec Unsupported' Exit 10 EndIf
$_Line = Split(Join(Split($_oExec.StdOut.ReadAll + $_oExec.StdErr.ReadAll,CHR(13)),''),CHR(10))[0]
$_Response = IIf($_Line, 1, 0)
If $_Response
$_Count = $_Tries
EndIf
$_Count = $_Count + 1
If $_Count < $_Tries Sleep 0.25 EndIf
Until $_Count >= $_Tries
; If FLAG >= 0, return success/failure - otherwise return IP address
If $_FLAG >= 0
$Ping = $_Response
Else
If Not $_Response
$Ping = '0.0.0.0'
Else
; In this mode we return the IP address - we should have the HOSTNAME
; handle the 'duh' factor for times when we get the IP address instead!
If InStr($_Line,'[') > 0
$Ping= Split(Join(Split($_Line,']',-1),'['), '[')[1]
Else
$Ping = Split(Split($_Line,' ',-1)[1], ':')[0]
EndIf
EndIf
EndIf
Exit Not $_Response ; set the error code
EndFunction