Co
|
(MM club member)
|
2003-12-29 04:36 PM
|
|
|
|
|
ScheduleTask - Array problem
|
|
Hi Everybody,
I have two scripts that uses the Scheduletask UDF. A script which schedule a task on a single computer and one that schedule a task on multiple computers. The first one works great but the second one gives an Error 1 - Incorrect function. I have tried everything but I cann't solve the problem
Someone any idea??
Happy New Year !!! Code:
;Schedule a task on a single computer ; ; ;Dependencies: UDF's: Scheduletask ; Tools: Jt.exe
; Calling UDF's ;-------------- Call "@ScriptDir\UDF\Scheduletask.udf" Break On
$name='sync_scripts_dir' $comp='comp1' $date='TODAY' $time='17:30' $type='ONCE' $cmd='\\comp1\Scripts\kix\sync_scripts_dir.exe' ;$user='admin' ;$pw='adminpw' ;$comment='test' ;$jt= 'c:\jt.exe' ?@ERROR scheduletask($name, $comp, $date, $time, $type, $cmd);, $user, $pw) ?@ERROR ? @SERROR Exit
Code:
;Schedule a task on multiple computers ; ; ;Dependencies: UDF's: Scheduletask, Serialtime, DateMath, SerialDate, abs. ; ; Netview2, Osid ; Service: Task Scheduler must be installed and running. ; Tools: Jt.exe
; Calling UDF's ;-------------- Break On Call "@ScriptDir\UDF\Scheduletask.udf" Call "@ScriptDir\UDF\Serialtime_hours.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 $type='ONCE' $cmd='c:\windows\notepad.exe' $timediff='00:30' $time='16:30'
; 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 ; ; ;$time=serialtime(serialtime($time)+ serialtime($timediff)) ; Date ;------------------------------ ; ;If $time='00:00' OR $time='24:00' ; $date= DateMath($date, 1) ;EndIf
; Schedule Task ;------------------------------ ; $rc=scheduletask($name, $comp, $date, $time, $type, $cmd) ? 'Error '+@ERROR+' - '+@SERROR
Next
;Get $rc
Exit
UDF: ScheduleTask UDF: Serialtime UDF: Datemath UDF: SerialDate UDF: Abs UDF: NetView2 UDF: OSID
|
ShaneEP
|
(MM club member)
|
2003-12-29 06:08 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
What with the line in the first section..
Code:
scheduletask($name, $comp, $date, $time, $type, $cmd);, $user, $pw)
Shouldnt it be something like..
Code:
scheduletask($name, $comp, $date, $time, $type, $cmd, , $user, $pw)
Are you using an older version of the ScheduleTask() that didnt have the cmd prms option?
|
ShaneEP
|
(MM club member)
|
2003-12-29 06:11 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Also...Maybe it is something with the @DATE format that JT doesnt like?
$date=@DATE
Does it work without an error if your change it to...
$date='TODAY'
Like the first example...
|
ShaneEP
|
(MM club member)
|
2003-12-29 06:14 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Also...Are you sure that the $comp is being assigned...Both lines that may assign it seem to be REMed out.
Code:
;$computers=netview2(Domain) ; ;$computers = 'comp1','comp2','comp3','comp4','comp5','comp6','comp7','comp8','comp9','comp10'; etc
|
Co
|
(MM club member)
|
2003-12-29 09:27 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Shane,
I have tried a lot of things:
1. A domain scan to search for Servers:
Code:
$computers=netview2(Domain)
and
Code:
$os = osid($comp)
If $os[1]='Win2K' AND $os[2]<>'Workstation' AND InStr($comp,"comp")<>0
I wanted to know if this causes the problem so i used instead:
Code:
$computers = 'comp1','comp2','comp3','comp4','comp5','comp6','comp7','comp8','comp9','comp10'; etc
The ; before $computers is a typo and isn't the problem that I meantion.
2. When the script starts every 30 minutes a new task it balances the network load:
Code:
$timediff='00:30'
$time='16:30'
Code:
;$time=serialtime(serialtime($time)+ serialtime($timediff))
; Date;------------------------------
;
;If $time='00:00' OR $time='24:00'
; $date= DateMath($date, 1)
;EndIf
I wanted to know if this part of the script causes the problem so i only used: $time='16:30'
If you delete all the code with an ; before it you see that the first and second script is almost the same. ScheduleTask is the only UDF that is called. The different part is:
Code:
$computers = 'comp1','comp2','comp3','comp4','comp5','comp6','comp7','comp8','comp9','comp10'
For Each $comp In $computers
$rc=scheduletask($name, $comp, $date, $time, $type, $cmd)
? 'Error '+@ERROR+' - '+@SERROR
Next
So, The problem must be in this piece of the code.. in combination with the ScheduleTask UDF.
Ps. The UDF versions are the ones I found on the UDF forums of KORG and Scriptlogic. See the links in the first post.
De beste wensen en een gelukkig nieuw jaar
Best wishes and a happy new year
|
ShaneEP
|
(MM club member)
|
2003-12-29 10:13 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
I know the ScheduleTask() works with an array. I am currently doing some testing using this type of scheduling and it works fine. One of the only difference between the first and second code above is the Date format which I already mentioned (see below)...Have you tried it yet by any chance? Other than that Im all out of ideas. I figured the computers being REMed out was a typo...Just thought I would throw it out there...
Quote:
Also...Maybe it is something with the @DATE format that JT doesnt like?
$date=@DATE
Does it work without an error if your change it to...
$date='TODAY'
Like the first example...
|
Co
|
(MM club member)
|
2003-12-29 10:26 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
I let you know in 9 hours...
|
|
Re: ScheduleTask - Array problem
|
|
Step through the code by using DEBUG ON to find the exact line where the script fails.
|
Co
|
(MM club member)
|
2003-12-30 08:56 AM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Shane,
You had it right. The problem is: Code:
$date = @date
There is a reason why I used this code: Every 30 minutes a new task will be scheduled. There is a possiblity that tasks will be scheduled the next day. That's why I used this code: Code:
If $time='00:00' OR $time='24:00' $date = DateMath($date, 1) EndIf
The problem is the date form. I have to find a way to change YYYY/MM/DD into MM/DD/YYYY.
UDF: Datemath
Quote:
Date parameters must be in the form of YYYY/MM/DD.
If a date is passed as "date1" and a number of days is passed as integer, the resulting date will be returned in the form of YYYY/MM/DD
Kixtart 4.22 Reference
Quote:
@Date Date (in the format YYYY/MM/DD)
www.jsiinc.com Quote:
Trigger 0: Type: Daily DaysInterval: 1 StartDate: 04/30/2000 EndDate: 00/00/0000 StartTime: 17:30 MinutesDuration: 0 MinutesInterval: 0 Flags: HasEndDate = 0 KillAtDuration = 0 Disabled = 0
De beste wensen en een gelukkig nieuw jaar Best wishes and a happy new year
|
Co
|
(MM club member)
|
2003-12-30 09:17 AM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
A simple search has given me the answer:
Date format
Quote:
well, you can use @date macro and re-order it's fields.
well, you also can simply do:
"date in weird order: @monthno/@mdayno/@year
Thanks Lonkero!
De beste wensen en een gelukkig nieuw jaar
Best wishes and a happy new year
|
Co
|
(MM club member)
|
2003-12-30 09:36 AM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Sorry Lonkero,
Jochen's code is better...
De beste wensen en een gelukkig nieuw jaar Best wishes and a happy new year
|
Co
|
(MM club member)
|
2003-12-30 10:25 AM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Mmm, It works but I'm not really satisfied.
Code:
For Each $comp In $computers
; filter
;------------------------------
;$os = osid($comp)
;
;If $os[1]='Win2K' AND $os[2]<>'Workstation' AND InStr($comp,"comp")<>0
;
;
$time=serialtime(serialtime($time)+ serialtime($timediff))
; Date
;------------------------------
;
? $time
? $date
$d = Split($date,'/')[1] + '/' + Split($date,'/')[2] + '/' + Split($date,'/')[0]
? $d
; Schedule Task
;------------------------------
;
$rc=scheduletask($name, $comp, $d, $time, $type, $cmd)
? 'Error '+@ERROR+' - '+@SERROR
Next
Changing the date format works OK. When time is for example 23:59 there is a problem because the date will not change in next day's date.
I have to change this part. When time has past midnight the date must be changed to next day's date....
Code:
If $time='00:00' OR $time='24:00'
$date= DateMath($date, 1)
EndIf
Quote:
23:29
2003/12/30
12/30/2003
Error 0 - The operation completed successfully
UDF Serialtime 0
23:59
2003/12/30
12/30/2003
Error 0 - The operation completed successfully
UDF Serialtime 0
-1
2003/12/30
12/30/2003
Error 1 - Incorrect function.
UDF Serialtime 1
UDF Serialtime 0
-1
2003/12/30
12/30/2003
Error 1 - Incorrect function.
UDF Serialtime 1
Sealeopard's Serialtime UDF without seconds and miliseconds
Code:
Function serialtime($strtime)
Dim $hours, $minutes
If InStr($strtime,':')
$strtime=Split($strtime,':')
Select
Case Ubound($strtime)<1
ReDim preserve $strtime[1]
Case Ubound($strtime)>1
$serialtime=-1
Exit 87
EndSelect
$hours=Val($strtime[0])
If $hours<0 OR $hours>23
$serialtime=-1
Exit 87
EndIf
$minutes=Val($strtime[1])
If $minutes<0 OR $minutes>59
$serialtime=-1
Exit 87
EndIf
$serialtime=0.0+($hours*3600)+($minutes*60)
Else
$strtime=Val(CDbl($strtime)*1000)
If $strtime<=86400000 AND $strtime>=0
$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)
$serialtime=$hours+':'+$minutes
Else
? 'UDF Serialtime' +Chr(9)+@ERROR+Chr(9)+$serialtime
$serialtime='-1'
Exit 87
EndIf
EndIf
EndFunction
Someone any ideas??
De beste wensen en een gelukkig nieuw jaar
Best wishes and a happy new year
|
Co
|
(MM club member)
|
2003-12-30 02:06 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
I thought I had the solution but there are still problems. The DateTimeDiff UDF should solve the problem. Probably I'm doing something wrong...
The UDF returns strange dates:
Code:
$dd = datetimediff($date+$time,$nextday+'00:00') gives 0000/02/16 00:00
$dd = datetimediff($date+$time,$nextday+'24:00') gives 0000/03/10 00:00
Code:
$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]
? 'Time before Task: '$time ? 'Date YYYY/MM/DD before Task: '$date ? 'Date MM/DD/YYYY before Task: '$d ? $comp
; Schedule Task ;------------------------------ $rc=scheduletask($name, $comp, $d, $time, $type, $cmd) ? 'Error '+@ERROR+' - '+@SERROR
; Date /Time ;------------------------------ $Nextday = DateMath($date, 1) ;Date YYYY/MM/DD $dd = datetimediff($date+$time,$nextday+'00:00') ? $nextday ? $dd ;$td=TIMEDIFF($time,'24:00')
$time=serialtime(serialtime($time)+ serialtime($timediff))
? 'New starttime: '$time ? 'Date YYYY/MM/DD After changing starttime: '$date
Next
Quote:
Time before Task: 23:29 Date YYYY/MM/DD before Task: 2003/12/30 Date MM/DD/YYYY before Task: 12/30/2003 comp1 Error 0 - The operation completed successfully. 2003/12/31 0000/02/16 00:00 New starttime: 23:59 Date YYYY/MM/DD After changing starttime: 2003/12/30 Time before Task: 23:59 Date YYYY/MM/DD before Task: 2003/12/30 Date MM/DD/YYYY before Task: 12/30/2003 comp2 Error 0 - The operation completed successfully. 2003/12/31 0000/02/16 00:00 UDF Serialtime 0 New starttime: -1 Date YYYY/MM/DD After changing starttime: 2003/12/30 Time before Task: -1 Date YYYY/MM/DD before Task: 2003/12/30 Date MM/DD/YYYY before Task: 12/30/2003 comp3 Error 1 - Incorrect function.
De beste wensen en een gelukkig nieuw jaar Best wishes and a happy new year
|
|
Re: ScheduleTask - Array problem
|
|
I will update the ScheduleTask UDF to accept both time formats MM/DD/YYYY and YYYY/MM/DD.
DateTimeDiff: What does $dd = datetimediff($date+$time,$nextday+' 00:00') give you? Please not the additional space between the date and the time!
|
Co
|
(MM club member)
|
2003-12-30 05:29 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Since the serialtime udf don't change the date after midnight I had to find a way to change it.
When $time + $timediff gives a time in the next day the date must changed with one day: 23:45 + 00:30 = 00:15 => date = date + 1.
When I use the timediff UDF 24:00 is at the begining of the day and not at the and so the diffence between 24:00 and 23:59 = 23:59
That's why I tried something with datetimediff: When the difference between 24:00 and 23:59 = 23:59 the difference between 30/12/2003 23:59 and 31/12/2003 24:00 must be one minute.
When the difference is less than 30minutes ($timediff) the date must change one day.
I Hope you understand what I intend to do. $dd = datetimediff($date+$time,$nextday+' 00:00') isn't a final part of the script and is accidently copied to this topic.
De beste wensen en een gelukkig nieuw jaar Best wishes and a happy new year
|
ShaneEP
|
(MM club member)
|
2003-12-30 07:12 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
And what happens if scheduled at 12:59 on 12/31/2003? Will it schedule it for 01:29 on 12/32/2003?
Date increments like this are always tough.
Glad you got the ScheduleTask() to work though.
|
Co
|
(MM club member)
|
2003-12-30 10:16 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Shane,
The time counts in 24hours format and not in an AM/PM format. The date goes from 31/12/2003 to 1/1/2004. So that is not the problem.
Please reply if you have any other ideas
De beste wensen en een gelukkig nieuw jaar Best wishes and a happy new year
|
ShaneEP
|
(MM club member)
|
2003-12-31 12:47 AM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
I was able to get the date to change with below code. If anyone sees any problems with it let me know. With the 76 computers it scheduled them all 30 minutes apart rolling into two different days and a different month. Seemed to work fine. Just need to replace the ? 'Task will be scheduled ...' line with the actual ScheduleTask() line. Let me know what you think.
Code:
$computers = 'comp1','comp2','comp3','comp4','comp5','comp6','comp7','comp8','comp9','comp10', 'comp11','comp12','comp13','comp14','comp15','comp16','comp17','comp18','comp19','comp20','comp21', 'comp22','comp23','comp24','comp25','comp26','comp27','comp28','comp29','comp30','comp31','comp32', 'comp33','comp34','comp35','comp36','comp37','comp38','comp39','comp40','comp41','comp42','comp43', 'comp44','comp45','comp46','comp47','comp48','comp49','comp50','comp51','comp52','comp53','comp54', 'comp55','comp56','comp57','comp58','comp59','comp60','comp61','comp62','comp63','comp64','comp65', 'comp66','comp67','comp68','comp69','comp70','comp71','comp72','comp73','comp74','comp75','comp76' $time='16:30' $timediff='00:30' $starthour=Split($time,':')[0] $date = @date For Each $comp In $computers $d = Split($date,'/')[1] + '/' + Split($date,'/')[2] + '/' + Split($date,'/')[0] ? 'Task will be scheduled on '+$comp+' on '+$d+' at '+$time ? If serialtime($time)+serialtime($timediff) > 86400 $time = '00:'+Split($time,':')[1] $time = serialtime(serialtime($time)-serialtime($timediff)) Else $time=serialtime(serialtime($time)+serialtime($timediff)) Endif $hour=Split($time,':')[0] $minute=Split($time,':')[1] If $hour<$starthour If $rollover=1 $date=DateMath($date, 1) $rollover=0 Endif Else $rollover=1 Endif Next get $
|
ShaneEP
|
(MM club member)
|
2003-12-31 02:02 AM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
I re-wrote the SerialTime() UDF to handle day roll-overs to simplify the below code a little bit.
Code:
$computers = 'comp1','comp2','comp3','comp4','comp5','comp6','comp7','comp8','comp9','comp10', 'comp11','comp12','comp13','comp14','comp15','comp16','comp17','comp18','comp19','comp20','comp21', 'comp22','comp23','comp24','comp25','comp26','comp27','comp28','comp29','comp30','comp31','comp32', 'comp33','comp34','comp35','comp36','comp37','comp38','comp39','comp40','comp41','comp42','comp43', 'comp44','comp45','comp46','comp47','comp48','comp49','comp50','comp51','comp52','comp53','comp54', 'comp55','comp56','comp57','comp58','comp59','comp60','comp61','comp62','comp63','comp64','comp65', 'comp66','comp67','comp68','comp69','comp70','comp71','comp72','comp73','comp74','comp75','comp76' $time='16:30' $timediff='00:30' $starthour=Split($time,':')[0] $date = @date For Each $comp In $computers $d = Split($date,'/')[1] + '/' + Split($date,'/')[2] + '/' + Split($date,'/')[0] ? 'Task will be scheduled on '+$comp+' on '+$d+' at '+$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 $
New SerialTime()
Code:
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
|
Co
|
(MM club member)
|
2003-12-31 03:36 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
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
|
ShaneEP
|
(MM club member)
|
2003-12-31 03:54 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Awesome...Im glad it worked for you. Let us know if you have any problems when you get back in the office on the 5th. Hope you enjoy your vacation.
|
Les
|
(KiX Master)
|
2003-12-31 04:14 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Quote:
When there are longlines in the code I confess, I'm guilty but please don't call the Police....
This is not the catholic church here. You cannot knowingly sin on Saturday with the intention of confessing on Sunday and expect to have your sins absolved.
BTW, that long line would be very easy to break into shorter ones without breaking the code.
|
Co
|
(MM club member)
|
2004-01-01 03:08 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
LOL.. I'm a catholic...
|
|
Re: ScheduleTask - Array problem
|
|
ScheduleTask() has already been updated to allow both YYYY/MM/DD and MM/DD/YYYY date inputs.
I'll start making a new DateTimeMath() UDF that will allow more complex date-time manipulations in addition to just calculating the difference between two dates or times. I already have a couple of ideas for this, but it might take me a week or two.
|
Co
|
(MM club member)
|
2004-01-02 11:15 AM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Thanks Jens
|
Co
|
(MM club member)
|
2004-01-05 11:03 AM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Shane, Jens,
At work it works great. I didn't changed the UDF's since I posted the full script. Next step is to update the ScheduleTask() UDF.
Code:
For Each $comp In $computers
; filter ;------------------------------ ;$os = osid($comp) ; ;If $os[1]='Win2K' AND $os[2]<>'Workstation' AND InStr($comp,"comp")<>0
; 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 $time='24:00' $time='00:00' $date=DateMath($date, 1) EndIf If $day>0 $date=DateMath($date, $day) EndIf
; 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
Next
There was a small problem at 24:00
Quote:
Task will be scheduled on comp1 on 01/05/2004 at 24:00 Error 1 - Incorrect function.
Task will be scheduled on comp2 on 01/06/2004 at 00:30 Error 0 - The operation completed successfully.
I modified the script with this peace of code: Code:
If $time='24:00' $time='00:00' $date=DateMath($date, 1) EndIf
Problem solved:
Quote:
Task will be scheduled on comp1 on 01/06/2004 at 00:00 Error 0 - The operation completed successfully.
Task will be scheduled on comp2 on 01/06/2004 at 00:30 Error 0 - The operation completed successfully.
Thanks guy's!
|
Co
|
(MM club member)
|
2004-01-05 12:46 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Jens,
I have updated the script with the latest version of ScheduleTask (). It gives an error 87:
Quote:
Task will be scheduled on comp1 on 2004/01/05 at 23:58
Error 87 - The parameter is incorrect.
Task will be scheduled on comp2 on 2004/01/06 at 00:28
Error 87 - The parameter is incorrect.
I have changed $d in $date and remmed out d$:
Code:
For Each $comp In $computers
; filter
;------------------------------
;$os = osid($comp)
;
;If $os[1]='Win2K' AND $os[2]<>'Workstation' AND InStr($comp,"comp")<>0
; 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 $time='24:00'
$time='00:00'
$date=DateMath($date, 1)
EndIf
If $day>0
$date=DateMath($date, $day)
EndIf
; Date Format
;------------
;$d = Split($date,'/')[1] + '/' + Split($date,'/')[2] + '/' + Split($date,'/')[0]
; Schedule Task
;------------------------------
?''
? 'Task will be scheduled on '+$comp+' on '+$date+' at '+$time
$rc=scheduletask($name, $comp, $date, $time, $type, $cmd)
? 'Error '+@ERROR+' - '+@SERROR
Next
|
ShaneEP
|
(MM club member)
|
2004-01-05 07:42 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
I dont see $date getting defined if it is not over a day...Maybe I missed something though.
|
ShaneEP
|
(MM club member)
|
2004-01-05 07:43 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Maybe...
Code:
If $day>0 $date=DateMath($date, $day) EndIf
Should be...
Code:
If $day>0 $date=DateMath($date, $day) Else $date=@date EndIf
|
Co
|
(MM club member)
|
2004-01-06 08:55 AM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Shane,
Sorry, The only code I showed is the FOR NEXT loop because all other parts of the script doesn't changed. I had to let you know...
Jens modified the ScheduleTask(). He added this code to the UDF:
Code:
select
case $date='TODAY'
; valid format
case len($date)<>10
exit 87
case left($date,3)='\'
; valid format
case left($date,5)='\'
; reformat date
$date=split($date,'\')
$date=$date[1]+'\'+$date[2]+'\'+$date[0]
case 1
exit 87
endselect
That's why I remmed out $d(See the full script some topics ago) and changed $d in $date.
Code:
$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
Code:
;$d = Split($date,'/')[1] + '/' + Split($date,'/')[2] + '/' + Split($date,'/')[0]
;Schedule Task
;------------------------------
?''
? 'Task will be scheduled on '+$comp+' on '+$date+' at '+$time
$rc=scheduletask($name, $comp, $date, $time, $type, $cmd)
? 'Error '+@ERROR+' - '+@SERROR
|
Co
|
(MM club member)
|
2004-01-06 09:13 AM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Shane,
I'm not sure this is what you meant with your last post:
Replace: Code:
If $time='24:00' $time='00:00' $date=DateMath($date, 1) EndIf If $day>0 $date=DateMath($date, $day) EndIf
for:
Code:
If $day>0 $date=DateMath($date, $day) Else $date=@date EndIf
unfortunately, It doesn't work
Quote:
Task will be scheduled on comp1 on 01/06/2004 at 24:00 Error 1 - Incorrect function.
Task will be scheduled on comp2 on 01/07/2004 at 00:30 Error 0 - The operation completed successfully.
|
Co
|
(MM club member)
|
2004-01-06 09:48 AM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
MMMM,
There is a difference between the added code in ScheduleTask and $d:
ScheduleTask:
Code:
$date=split($date,'\')
$date=$date[1]+'\'+$date[2]+'\'+$date[0]
$d:
Code:
$d = Split($date,'/')[1] + '/' + Split($date,'/')[2] + '/' + Split($date,'/')[0]
I have changed all \ in / but there is still an error 87
...I give up, I have a working script with the old version of ScheduleTask and variable $d...
|
ShaneEP
|
(MM club member)
|
2004-01-06 05:56 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
You're right...The case select portion that Jens added was a little off. The usage of the LEFT function was wrong.
Try Replacing the following...
Code:
select
case $date='TODAY'
; valid format
case len($date)<>10
exit 87
case left($date,3)='\'
; valid format
case left($date,5)='\'
; reformat date
$date=split($date,'\')
$date=$date[1]+'\'+$date[2]+'\'+$date[0]
case 1
exit 87
endselect
With this...
Code:
select
case $date='TODAY'
; valid format
case len($date)<>10
exit 87
case right(left($date,3),1)='/'
; valid format
case right(left($date,5),1)='/'
; reformat date
$date=split($date,'/')
$date=$date[1]+'/'+$date[2]+'/'+$date[0]
case 1
exit 87
endselect
|
|
Re: ScheduleTask - Array problem
|
|
Darn, that happens when you try to improve an UDF while feeding a baby and not testing it. I'll correct that at once with a correctly used SUBSTR().
|
Co
|
(MM club member)
|
2004-01-06 10:15 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Shane,
I did but there was still an error 87...
|
Co
|
(MM club member)
|
2004-01-06 10:16 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Jens,
Lol, I know how it feels... the second one is on his way..
|
Co
|
(MM club member)
|
2004-01-06 10:18 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Sorry Shane your code is different.. I'll test it tommorow..
|
Co
|
(MM club member)
|
2004-01-07 10:44 AM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Shane,
FANTASTIC!!!
Quote:
Task will be scheduled on comp1 on 2004/01/07 at 23:58
Error 0 - The operation completed successfully.
Task will be scheduled on comp2 on 2004/01/08 at 00:28
Error 0 - The operation completed successfully.
I replaced the Select..Endselect Jens added to Scheduletask() with your code . deleted $d and changed $d in $date in other parts of the code and it now works perfect.
Thanks!
|
|
Re: ScheduleTask - Array problem
|
|
BTW, I already corrected the ScheduleTask() UDF with a corrected version utilizing SUBSTR().
|
Co
|
(MM club member)
|
2004-01-07 07:14 PM
|
|
|
|
|
Re: ScheduleTask - Array problem
|
|
Jens,
I didn't tested it but I think you have to replace the backslashes with slashes since the date format must be MM/DD/YYYY... Code:
case substr($date,3,1)='\' ; valid format case substr($date,5,1)='\' ; reformat date $date=split($date,'\') $date=$date[1]+'\'+$date[2]+'\'+$date[0]
Must be...
Code:
case substr($date,3,1)='/' ; valid format case substr($date,5,1)='/' ; reformat date $date=split($date,'/') $date=$date[1]+'/'+$date[2]+'/'+$date[0]
Feeding the baby again.. or did you had a very short and broken night
|
|
Re: ScheduleTask - Array problem
|
|
Done. Should test UDFs before posting them
Apologies for this.
|