Hey Kix geniuses,

I am just sharing my kix program I made. I got the function and ldap query from the gurus here on the kix forum. You guys rock. You are worth more than you are paid by far. This works great to keep PCs off every night I run this program using job schedular on windows 2003 server. Keeps track of pcs left on and it only attempts to shut off PCs that are actually on. It checks to see if they are alive(ping test). Then picks the correct OS shutdown command. We had issues with windows shutdown not working on 2000 machines so I modified it to differentiate and use psshutdown instead. works awesome. We had many issues with people leaving PCs on for weeks or months. never shutting them down. Not any more as long as intellishutdown is run. Enjoy! Oh yeah with the LDAP query no more editing an array list. IT is know purely automated no more maintenance.
IT Daddy

 Code:

;*****************************************************************
;                 IntelliShutdown
;*****************************************************************
; getting log files ready and cleaned out.
; warning giving admin time to shut off.

 
? 'you have 20 seconds to stop this program' 
? 'else it will shutdown all PCs at Branchs'
? 'session will drop if you click x in upper corner'
? 'but shutdown will stop nonetheless'
sleep 30
 
Shell "CMD.EXE /C xcopy clean.txt failure.txt /y"
Shell "CMD.EXE /C xcopy clean2.txt success.txt /y"


;*******************************************************************************************************
;LDAP Branchx delclare and fill portion

;*************declare and fill arrays here*****************************

Dim $Branch1, $Branch2, $Branch3, $Branch4

;fnLDAPQuery(WHAT, Optional FROM, Optional FILTER, Optional ORDER BY, Optional SCOPE, Optional USER, Optional PASSWORD)
$Branch1 = fnLDAPQuery('Name','GC://OU=Computers,OU=ForthAve,OU=funnycu,dc=funnycu,dc=priv','(&(objectClass=Computer)(Name=*))')
$Branch2 = fnLDAPQuery('Name','GC://OU=Computers,OU=EighthSt,OU=funnycu,dc=funnycu,dc=priv','(&(objectClass=Computer)(Name=*))')
$Branch3 = fnLDAPQuery('Name','GC://OU=Computers,OU=PostRd,OU=funnycu,dc=funnycu,dc=priv','(&(objectClass=Computer)(Name=*))')
$Branch4 = fnLDAPQuery('Name','GC://OU=Computers,OU=ParkDr,OU=funnycu,dc=funnycu,dc=priv','(&(objectClass=Computer)(Name=*))')

;****************************************************
$Skip1 = "pc1", "pc5","pc7","pc9"
;$Skip2 = 
;$Skip3 =
;$Skip4 =
 
;*********************************************************************************************
For Each $Element In $Branch1

          Shell "cmd.exe /c ping "+ $Element + " -n 2"
 	  IF @ERROR = 0 
	     If AScan($Skip1,$Element) = -1
                 Shell "net use z: \\" + $Element + "\c$" 
                 If Exist("Z:\WINDOWS") <> 0
                    Shell 'CMD.EXE /C shutdown -m \\$Element -f -s ' 
	            IF @ERROR = 0 $RC = REDIRECTOUTPUT (success.txt, 0) ? 'XP: ' + $Element Endif   
                     
                 Endif
                 If Exist("Z:\WINNT") <> 0
    	            Shell 'CMD.EXE /C psshutdown \\$Element -f -k '   
                    IF @ERROR = 0 $RC = REDIRECTOUTPUT (success.txt, 0) ? '2k: ' +$Element Endif   
                     
	         Endif 
	     Endif	
	     Shell "CMD.EXE /C net use z: /delete"
          Endif	
Next

For Each $Element In $Branch2

          Shell "cmd.exe /c ping "+ $Element + " -n 2"
 	  IF @ERROR = 0 
	     If AScan($Skip2,$Element) = -1
                 Shell "net use z: \\" + $Element + "\c$" 
                 If Exist("Z:\WINDOWS") <> 0
                    Shell 'CMD.EXE /C shutdown -m \\$Element -f -s ' 
	            IF @ERROR = 0 $RC = REDIRECTOUTPUT (success.txt, 0) ? 'XP: ' + $Element Endif   
                     
                 Endif
                 If Exist("Z:\WINNT") <> 0
    	            Shell 'CMD.EXE /C psshutdown \\$Element -f -k '   
                    IF @ERROR = 0 $RC = REDIRECTOUTPUT (success.txt, 0) ? '2k: ' +$Element Endif   
                     
	         Endif 
	     Endif	
	     Shell "CMD.EXE /C net use z: /delete"
          Endif	
Next

For Each $Element In $Branch3

          Shell "cmd.exe /c ping "+ $Element + " -n 2"
 	  IF @ERROR = 0 
	     If AScan($Skip3,$Element) = -1
                 Shell "net use z: \\" + $Element + "\c$" 
                 If Exist("Z:\WINDOWS") <> 0
                    Shell 'CMD.EXE /C shutdown -m \\$Element -f -s ' 
	            IF @ERROR = 0 $RC = REDIRECTOUTPUT (success.txt, 0) ? 'XP: ' + $Element Endif   
                     
                 Endif
                 If Exist("Z:\WINNT") <> 0
    	            Shell 'CMD.EXE /C psshutdown \\$Element -f -k '   
                    IF @ERROR = 0 $RC = REDIRECTOUTPUT (success.txt, 0) ? '2k: ' +$Element Endif   
                     
	         Endif 
	     Endif	
	     Shell "CMD.EXE /C net use z: /delete"
          Endif	
Next

For Each $Element In $Branch4

          Shell "cmd.exe /c ping "+ $Element + " -n 2"
 	  IF @ERROR = 0 
	     If AScan($Skip4,$Element) = -1
                 Shell "net use z: \\" + $Element + "\c$" 
                 If Exist("Z:\WINDOWS") <> 0
                    Shell 'CMD.EXE /C shutdown -m \\$Element -f -s ' 
	            IF @ERROR = 0 $RC = REDIRECTOUTPUT (success.txt, 0) ? 'XP: ' + $Element Endif   
                     
                 Endif
                 If Exist("Z:\WINNT") <> 0
    	            Shell 'CMD.EXE /C psshutdown \\$Element -f -k '   
                    IF @ERROR = 0 $RC = REDIRECTOUTPUT (success.txt, 0) ? '2k: ' +$Element Endif   
                     
	         Endif 
	     Endif	
	     Shell "CMD.EXE /C net use z: /delete"
          Endif	
Next


;***************************************************************************************

; LDAP function for query above


Function fnLDAPQuery($What,Optional $From,Optional $Filter,Optional $OrderBy,Optional $Scope,Optional $User,Optional $Pswd)
  Dim $oCon,$oCMD,$oRS,$sQ,$aR,$C,$R
  $sQ="<"+Iif($From="","LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext"),$From)+">;"+$Filter+";"+Iif(VarType($What)>8192,Join($What,','),$What)+";"+Iif($Scope<>"base" AND $Scope<>"onelevel","subtree",$Scope)
  $oCon=CreateObject("ADODB.Connection")
  $oCon.Provider="ADsDSOObject"
  $oCon.Properties("Encrypt Password").Value=1
  $oCon.Properties("ADSI Flag").Value=1
  If $User AND $Pswd
    $oCon.Properties("User ID").Value=$User
    $oCon.Properties("Password").Value=$Pswd
  EndIf
  $oCon.Open("Active Directory Provider")
     
  $oCMD=CreateObject("ADODB.Command")
  $oCMD.ActiveConnection=$oCon
  $oCMD.CommandText=$sQ
  $oCMD.Properties("Page Size").Value=1000
  $oCMD.Properties("Timeout").Value=30
  $oCMD.Properties("Cache Results").Value=0
    
  If InStr($OrderBy,"distinguishedName")
    $oRS=CreateObject("ADODB.Recordset")
    $oRS.CursorLocation=3
    $oRS.Sort=$OrderBy
    $oRS.Open($sQ,$oCon,0,1,1)
  Else
    If $OrderBy
      $oCMD.Properties("Sort On").Value=$OrderBy
    EndIf
    $oRS=$oCMD.Execute
  EndIf
  If @ERROR Exit @ERROR EndIf
  If $oRS.BOF AND $oRS.EOF Exit @ERROR EndIf
    
  $aR = $oRS.GetRows()
  Dim $aFR[Ubound($aR,2),Ubound($aR,1)]
  For $R=0 to Ubound($aR,2)
    For $C=0 to Ubound($aR,1)
       $aFR[$R,$C]=$aR[$C,$R]
    Next
  Next
  $fnLDAPQuery=$aFR
EndFunction










 
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin