Page 1 of 1 1
Topic Options
#46666 - 2003-10-14 04:15 PM Scheduletask() - Incorrect function ???
Co Offline
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 [Big Grin]
_________________________
Co


Top
#46667 - 2003-10-14 04:28 PM Re: Scheduletask() - Incorrect function ???
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You should not have changed it in the first place as it will check for the presence of JT.EXE if provided the path to is as optional parameter as you already do. Alternatively, add the additional path to the array if you're sure that JT.EXE will always be in only that one location. You should also not remove the .JOB sanity check so that the UDF can correctly delete potentially existing tasks.

Put a DEBUG ON into your code to see where exactly it fails and what the command line command is that is being created.

And please post code in between [CODE] tags.

[ 14. October 2003, 16:29: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#46668 - 2003-10-14 05:00 PM Re: Scheduletask() - Incorrect function ???
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1342
Loc: NL
When i debug it there isn't a error. It only appears when i execute the script normally.

ps. What's wrong about the way I used Code /Code?? I used it three times for two parts of a script and one complete script... [Confused]
_________________________
Co


Top
#46669 - 2003-10-14 05:06 PM Re: Scheduletask() - Incorrect function ???
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Sorry, I was missing indentations, makes it harder to read the code.

The script shoudl runt he same whether it's in debug mode or not as the same lines of code get executed. So, what you're saying is that if you run the exact same ocd but have DEBUG ON in the first line then it does work? Does it work without your customizations?
_________________________
There are two types of vessels, submarines and targets.

Top
#46670 - 2003-10-14 08:42 PM Re: Scheduletask() - Incorrect function ???
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1342
Loc: NL
It is OK,

I didn't use debug on but /d. For me it is the same. I think I know the reason why i didn't see the message: It was under the green debug-line [Big Grin] .
Do you think the changes i made causes this problem?
_________________________
Co


Top
#46671 - 2003-10-14 08:47 PM Re: Scheduletask() - Incorrect function ???
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
It shouldn't, however, the changes are unnecessary to begin with as you do have the option of A) hardcoding another potential location in the UDF as another path array element and B) provide the full path to JT.EXE as an optional parameter.
_________________________
There are two types of vessels, submarines and targets.

Top
#46672 - 2003-10-14 10:00 PM Re: Scheduletask() - Incorrect function ???
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1342
Loc: NL
I understand.. I had my reasons to make these changes..

Tommorow is a new day and then i will look further..

Thanks
_________________________
Co


Top
#46673 - 2003-10-15 09:37 AM Re: Scheduletask() - Incorrect function ???
Co Offline
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
#46674 - 2003-10-16 04:48 AM Re: Scheduletask() - Incorrect function ???
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I'll check into the @STARTDIR problem.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1183 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.058 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org