#46666 - 2003-10-14 04:15 PM
Scheduletask() - Incorrect function ???
|
Co
MM club member
 
Registered: 2000-11-20
Posts: 1342
Loc: NL
|
Hi eveybody,
I have made some changes to the Scheduletask() UDF. I have deleted: code:
; 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
And replaced it with:
code:
; filepath to jt.exe $jtexe= 'D:\scripts\tools\jt.exe'
The script ends with error 1 - Incorrect function. I have checked the script and BB in case it is a known problem but I can't find the solution.
code:
$name='test' $comp='testXPpc' $date='TODAY' $time='now' $type='ONCE' $user='admin' $pw='adminpw' $comment='test' $cmd='notepad' $jt= 'D:\scripts\tools\jt.exe' scheduletask($name, $comp, $date, $time, $type, $cmd, $user, $pw, $comment, $jt) ? @SERROR
:END Sleep 30 exit ; ;*********** ; ;FUNCTION ScheduleTask ;AUTHOR Jens Meyer (sealeopard@usa.net) ; ;To shorten this post i have deleted the info part. ; ;KIXTART BBS http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000060 ; Function scheduletask($name, $comp, $date, $time, $type, $cmd, optional $prms, optional $user, optional $pw, optional $comment, optional $typeargs, optional $jt) Dim $jtexe, $shellcmd
If $name='' OR $comp='' OR $date='' OR $time='' OR $type='' OR $cmd='' Exit 87 EndIf
; filepaths to jt.exe $jtexe= 'D:\scripts\tools\jt.exe'
; 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
WKIX32 - 4.22rc1 KIX32 - 4.22rc1 kix32 - 4.21 Windows XP SP1 (lokal + remote)-> Taskscheduler started
_________________________
Co
|
|
Top
|
|
|
|
#46673 - 2003-10-15 09:37 AM
Re: Scheduletask() - Incorrect function ???
|
Co
MM club member
 
Registered: 2000-11-20
Posts: 1342
Loc: NL
|
I had the problem also on a W2K Server. So I used the original UDF and put jt.exe and the kix file in the same directory. The Illegal function error was still there. When I changed:
code:
$jtexe[1]=@STARTDIR+'\jt.exe'
to
code:
$jtexe[1]='c:\jt.exe'
and copied jt.exe to c:\ the script ended succesful on both OS's.
code:
$name='test' $comp='sasntest' $date='TODAY' $time='now' $type='ONCE' $cmd='notepad' $user='admin' $pw='adminpw' ;$comment='test' ;$jt= 'c:\jt.exe' ?@ERROR scheduletask($name, $comp, $date, $time, $type, $cmd, $user, $pw) ?@ERROR ? @SERROR
:END Sleep 30 Exit
;FUNCTION ScheduleTask ; ;ACTION Schedules a task on any computer using the Task Scheduler ; ;AUTHOR Jens Meyer (sealeopard@usa.net) ; ;KIXTART BBS http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000060 ; 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='' ? @ERROR Exit 87 EndIf ; create an array of potential filepaths to jt.exe $jtexe[0]=$jt $jtexe[1]='c:\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 ? @ERROR Exit @ERROR EndFunction
[ 15. October 2003, 12:53: Message edited by: Co ]
_________________________
Co
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 400 anonymous users online.
|
|
|