Shane,

You are my man for the past year! And of course Jens, He created most of the udf's I have used for this script and he helped me a lot in the past.

There is still a error 1 code. I have until the 5th of januari free from work so I think my computers at home causes this problem. Both scripts are great!

Maybe Jens can change the serialtime and scheduletask UDF,s: Serialtime - Date change after midnight
scheduletask - Schedule a task with different date formats.

This is the complete script including all used UDF's except Netview2() and osid(). I also deleted the UDF comments to shorten the length of the code. When there are longlines in the code I confess, I'm guilty but please don't call the Police....

Code:
 
;Schedule a task on multiple computers
;
;
;Dependencies: UDF's: Scheduletask, Serialtime, DateMath, SerialDate, abs.
; Domain Scan and OS filter ; Netview2, Osid (Both UDF's aren't included in this script)
; Service: Task Scheduler must be installed and running.
; Tools: Jt.exe
Break On

; Calling UDF's
;--------------
;Call "@ScriptDir\UDF\Scheduletask.udf"
;Call "@ScriptDir\UDF\Serialtime.udf"
;Call "@ScriptDir\UDF\DateMath.udf"
;Call "@ScriptDir\UDF\SerialDate.udf"
;Call "@ScriptDir\UDF\abs.udf"
;Call "@ScriptDir\UDF\Netview2.udf"
;Call "@ScriptDir\UDF\Osid.udf"

; variables
;----------
Dim $computers, $comp, $name, $date, $type, $cmd, $timediff, $time, $rc


$name='test'
$date=@date ; '2003/12/31'
$type='ONCE'
$cmd='notepad'
$timediff='00:30'
$time='23:29'
$starthour=Split($time,':')[0]

; Domain scan
;------------------------------
;
;$computers=netview2(Domain)
;
$computers = 'comp1','comp2','comp3','comp4','comp5','comp6','comp7','comp8','comp9','comp10'; etc
For Each $comp In $computers

; filter
;------------------------------
;$os = osid($comp)
;
;If $os[1]='Win2K' AND $os[2]<>'Workstation' AND InStr($comp,"comp")<>0


; Date Format
;------------
$d = Split($date,'/')[1] + '/' + Split($date,'/')[2] + '/' + Split($date,'/')[0]


; Schedule Task
;------------------------------
? 'Task will be scheduled on '+$comp+' on '+$d+' at '+$time
$rc=scheduletask($name, $comp, $d, $time, $type, $cmd)
? 'Error '+@ERROR+' - '+@SERROR


; Date /Time
;------------------------------
$time=serialtime(serialtime($time)+serialtime($timediff))
$day=Val(Split($time,':')[0])
$hour=Split($time,':')[1]
$minute=Split($time,':')[2]
$time=$hour+':'+$minute
If $day>0
$date=DateMath($date, $day)
EndIf
Next
Get $

Exit

; Function serialtime
Function serialtime($strtime)
Dim $day,$days,$hours, $minutes, $seconds, $milliseconds
If InStr($strtime,':')
$strtime=Split($strtime,':')
Select
Case Ubound($strtime)<3
ReDim preserve $strtime[3]
If InStr($strtime[2],'.')
$strtime[3]=Right($strtime[2],Len($strtime[2])-InStr($strtime[2],'.'))
$strtime[2]=Left($strtime[2],InStr($strtime[2],'.')-1)
Else
$strtime[3]=0
EndIf
Case Ubound($strtime)>3
$serialtime=-1
Exit 87
EndSelect
$hours=Val($strtime[0])
If $hours>23
$days=Val($hours/24)
For $day=1 to $days
$hours=$hours-24
Next
Else
$days=0
EndIf
If $hours<0
$serialtime=-1
Exit 87
EndIf
$minutes=Val($strtime[1])
If $minutes<0 OR $minutes>59
$serialtime=-1
Exit 87
EndIf
$seconds=Val($strtime[2])
If $seconds<0 OR $seconds>59
$serialtime=-1
Exit 87
EndIf
$milliseconds=CDbl($strtime[3])
If $milliseconds<0 OR $milliseconds>999
$serialtime=-1
Exit 87
EndIf
$serialtime=0.0+($days*86400)+($hours*3600)+($minutes*60)+($seconds)+($milliseconds/1000)
Else
$strtime=Val(CDbl($strtime)*1000)
If $strtime>=0
If $strtime>86400000
$days=$strtime/86400000
For $day=1 to $days
$strtime=$strtime-86400000
Next
If Len($days)<2
$days=Right('00'+$days,2)
EndIf
Else
$days='00'
EndIf
$hours=$strtime/3600/1000
$strtime=$strtime-($hours*3600*1000)
$hours=Right('00'+$hours,2)
$minutes=$strtime/60/1000
$strtime=$strtime-($minutes*60*1000)
$minutes=Right('00'+$minutes,2)
$seconds=$strtime/1000
$strtime=$strtime-($seconds*1000)
$seconds=Right('00'+$seconds,2)
$milliseconds=Left($strtime,3)
$milliseconds=Right('000'+$milliseconds,3)
$serialtime=$days+':'+$hours+':'+$minutes+':'+$seconds+'.'+$milliseconds
Else
$serialtime='-1'
Exit 87
EndIf
EndIf
EndFunction

; Function scheduletask
Function scheduletask($name, $comp, $date, $time, $type, $cmd, optional $prms, optional $user, optional $pw, optional $comment, optional $typeargs, optional $jt)
Dim $jtexe[3], $shellcmd, $path

If $name='' OR $comp='' OR $date='' OR $time='' OR $type='' OR $cmd=''
Exit 87
EndIf

; create an array of potential filepaths to jt.exe
$jtexe[0]=$jt
$jtexe[1]=@STARTDIR+'\jt.exe'
$jtexe[2]=@SCRIPTDIR+'\jt.exe'
$jtexe[3]=@CURDIR+'\jt.exe'
$path=Split('%PATH%',';')
For Each $jt In $path
ReDim preserve $jtexe[Ubound($jtexe)+1]
$jtexe[Ubound($jtexe)]=Join(Split($jt+'\jt.exe','\\'),'\')
Next

; check each filepath for the presence of jt.exe
For Each $jt In $jtexe
If Exist($jt) AND NOT (GetFileAttr($jt) & 16) AND Ubound($jtexe)+1
$jtexe=$jt
EndIf
Next
Select
Case Ubound($jtexe)+1
Exit 2
Case NOT Exist($jtexe)
Exit 2
EndSelect

If Left($comp,2)<>'\\'
$comp='\\'+$comp
EndIf

If Right($name,4)<>'.job'
$name=$name+'.job'
EndIf

; delete a potentially existing task
$shellcmd = $jtexe
If $user AND $pw
$shellcmd = $shellcmd+ ' /SC "'+$user+'" "'+$pw+'"'
EndIf
$shellcmd = $shellcmd+ ' /SM '+$comp
$shellcmd = $shellcmd+ ' /SD "'+$name+'"'

Shell '%COMSPEC% /e:1024 /c '+$shellcmd+' >NUL 2>NUL'

$shellcmd = $jtexe

If $user AND $pw
$shellcmd = $shellcmd+ ' /SC "'+$user+'" "'+$pw+'"'
EndIf

$shellcmd = $shellcmd+ ' /SM '+$comp
$shellcmd = $shellcmd+ ' /SJ ApplicationName="'+$cmd+'"'

If $prms
$shellcmd = $shellcmd+ ' Parameters="'+$prms+'"'
EndIf

$shellcmd = $shellcmd+ ' WorkingDirectory="%SYSTEMROOT%"'
$shellcmd = $shellcmd+ ' Comment="'+$comment+'"'
$shellcmd = $shellcmd+ ' Creator="'+@userid+'"'
$shellcmd = $shellcmd+ ' Priority=Normal'
$shellcmd = $shellcmd+ ' MaxRunTime=3600000'
$shellcmd = $shellcmd+ ' DontStartIfOnBatteries=0'
$shellcmd = $shellcmd+ ' KillIfGoingOnBatteries=0'
$shellcmd = $shellcmd+ ' RunOnlyIfLoggedOn=0'
$shellcmd = $shellcmd+ ' SystemRequired=0'
$shellcmd = $shellcmd+ ' DeleteWhenDone=1'
$shellcmd = $shellcmd+ ' Suspend=0'
$shellcmd = $shellcmd+ ' StartOnlyIfIdle=0'
$shellcmd = $shellcmd+ ' KillOnIdleEnd=0'
$shellcmd = $shellcmd+ ' RestartOnIdleResume=0'
$shellcmd = $shellcmd+ ' Hidden=0'
$shellcmd = $shellcmd+ ' TaskFlags=0'

$shellcmd = $shellcmd+ ' /CTJ StartDate='+$date
$shellcmd = $shellcmd+ ' StartTime='+$time
$shellcmd = $shellcmd+ ' HasEndDate=0'
$shellcmd = $shellcmd+ ' KillAtDuration=0'
$shellcmd = $shellcmd+ ' Disabled=0'
$shellcmd = $shellcmd+ ' Type='+$type
If $typeargs
$shellcmd = $shellcmd+ ' TypeArguments='+$typeargs
EndIf
$shellcmd = $shellcmd+ ' /SAJ "'+$name+'"'

Shell '%COMSPEC% /e:1024 /c '+$shellcmd+' >NUL 2>NUL'
$scheduletask=@ERROR
Exit @ERROR
EndFunction

; Function DateMath
Function DateMath($ExpD1,$ExpD2)
Select
Case InStr($ExpD1,'/') AND InStr($ExpD2,'/')
; two date passed - return daysbetween integer
$DateMath=serialdate($ExpD1)-serialdate($ExpD2)
If $DateMath<0
$DateMath=$DateMath*-1
EndIf
Case InStr($ExpD1,'/') AND 1-InStr($ExpD2,'/')
; date and a number passed - return date
$ExpD2=0+$ExpD2
$Datemath=serialdate(serialdate($ExpD1)+$ExpD2)
Case 1 ; incorrect parameters passed
EndSelect
EndFunction


;Function serialdate
Function serialdate($ExpD)
Dim $z,$h,$a,$b,$c,$y,$m,$d
If InStr($ExpD,'/')
$ExpD=Split($ExpD,'/')
$y=Val($ExpD[0])
$m=Val($ExpD[1])
$d=Val($ExpD[2])
If $m<3
$m=$m+12
$y=$y-1
EndIf
$SerialDate=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
Else
$z=0+$ExpD+306
$h=100*$z-25
$a=$h/3652425
$b=$a-$a/4
$y=(100*$b+$h)/36525
$c=$b+$z-365*$y-$y/4
$m=(5*$c+456)/153
$d=$c-(153*$m-457)/5
If $m>12
$y=$y+1
$m=$m-12
EndIf
$SerialDate=Right('0000'+$y,4)+'/'+Right('00'+$m,2)+'/'+Right('00'+$d,2)
EndIf
EndFunction

Function abs($Expr)
;returns the absolute value of a number
$Expr=0+$Expr
If $Expr<0
$Expr=-1*$Expr
EndIf
$abs=$Expr
EndFunction

De beste wensen en een gelukkig nieuw jaar
Best wishes and a happy new year


_________________________
Co