;=================================================================
; Shutdown Computers
;=================================================================
Dim $objAdsPath, $obj, $filter[0]
$filter[0] = "computer"
$objADsPath = GetObject("LDAP://OU=Accounting,OU=Computers,DC=%Userdomain%,DC=internal")
If @Error = 0
$objAdsPath.filter = $filter
For Each $obj In $objAdsPath
$PcName = SUBSTR($obj.name, 4)
? $PcName
; Shell '"'+%COMSPEC%+'" /c ping -n 1 ' + $PcName + ' |find /C "TTL=" >nul'
$OSPing = Ping($PcName, 0, 1)
? $OSPing
$IP = Ping($PcName, 1, 1)
? $IP
If $OSPing = 1 AND Not InStr($IP, "192.168.10")
$ShellCMD = 'shutdown -s -f -m ' + $PcName + ' -t 300'
Shell $ShellCMD
? "shutting down " + $PcName
Else
? "computer not online, or is VPN"
Endif
Next
Else
? "Not able to connect to LDAP path."
Endif
;;; http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Board=7&Number=208164 ;;;
function Ping($Computer,$GetIP,optional $LoopCount,optional $TimeOut)
if $GetIP
dim $ip, $ipfile, $
$ipfile = @scriptdir + '\ip.txt'
shell '%Comspec% /q /e:1024 /c for /F "tokens=2 delims=[]" %%i IN ('+ chr(39)
+ '"ping ' + $Computer + ' -n 1 | find "]""' + chr(39) + ') do echo %%i >"' + $ipfile + '"'
$ = open(10,$ipfile,2) $ip = readline(10) $ = close(10) del $ipfile
if $ip
$Ping = $ip
else
$Ping = 'Bad IP address ' + $Computer + '!'
endif
exit 0
else
if $TimeOut
for $c = 0 to $LoopCount
shell '%Comspec% /C ping ' + $Computer + ' -n 1 -w ' + $TimeOut + ' | find /C "TTL=" > nul'
if @error = 0
$Ping = 1
exit 0
endif
next
else
for $c = 0 to $LoopCount
shell '%Comspec% /C ping ' + $Computer + ' | find /C "TTL=" > nul'
if @error = 0
$Ping = 1
exit 0
endif
next
endif
$Ping = 0
endif
endfunction