#115616 - 2004-03-06 01:53 PM
ScheduleTask()
|
attiahia
Hey THIS is FUN
Registered: 2000-03-27
Posts: 268
|
I am quite confused with the Jt.exe potential file paths part in ScheduleTask() function. If I am sure of JT.exe location, can I replace the following part of the function:
; 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
with just: $JT=’@curdir\jt.exe’
|
Top
|
|
|
|
#115617 - 2004-03-06 03:38 PM
Re: ScheduleTask()
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Why not do it simpler, you doing an array..
Code:
IF EXIST(@SCRIPTDIR+'\jt.exe')
;DO SCHEDULING
ENDIF
Let's look at the definitions of the macros you list:
@STARTDIR > Directory from which KiXtart was started
@SCRIPTDIR > Directory of current script
@CURDIR > Current directory
In the example you provided, these seem redundant.
Kent
|
Top
|
|
|
|
#115620 - 2004-03-07 07:17 AM
Re: ScheduleTask()
|
attiahia
Hey THIS is FUN
Registered: 2000-03-27
Posts: 268
|
Thanks lot gentlemen for your kind support.
For beginner like me (or even experts) simplify code usually is one of the criteria at building script. Therefore, I am just thinking what if we instead of this part (checking JT.exe existence) which contain about 20 lines of code, modify the script to generate error message if JT.exe was not found in the @Curdir then programmer will easily add the file.
Simplify code will allow easer debugging.
|
Top
|
|
|
|
#115622 - 2004-03-07 03:05 PM
Re: ScheduleTask()
|
Sealeopard
KiX Master
Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
|
Also, UDFs are supposed to be generalized functions that work in all kinds of circumstances. Not everybody puts, e.g. JT.EXE into the same directory as the script. Actualy, I'd consider it a best practive NOT to have a executable such as JT.EXE in the same directory as a KiXtart script.
You're welcome to modify UDFs on your own. However, as soon as you ask for help on such modified UDFs, I for example ahve to go throguht teh compleet UDF and trace down all the modifications you've potentially made and how they affect the UDF. And quiet frankly, I don't have time for such things. If you have a request for improvement, post it, and I'll incorporate it into the UDF.
_________________________
There are two types of vessels, submarines and targets.
|
Top
|
|
|
|
#115624 - 2004-03-07 04:23 PM
Re: ScheduleTask()
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
Well, Lonk, for some of us, reading, understanding, and modifying code from others is just another way to learn. Don't you think we would do the same if we had access to the O/S source? Maybe we'd close some Windows buffer overrun holes! I had access to the Unix SVR2 source and was credited with fixing a bug in the terminal session init code (WAY too many years ago).
Back to the topic...
The short answer to the original question is "yes", replacing the source determination code with a fixed path will work. In fact, I've done this and simply reference "JT.exe" since it is available via the system PATH or it isn't installed in my environment.
Jens appears to have written this piece of code to account for other people installing the JT executable in various locations. Since he isn't clarvoyant and can't know where you've installed it OR assume it's available via the PATH, this code searches the most common locations to insure it is available. It is an example of good coding when you are writing for a universal audience.
Changing is best done by commenting out the original code (or - heaven forbid!! temporarily using a GOTO to jump over it) and adding your own code changes. Follow this with lots of testing!! You should be aware that when you modify someone else's code, they shouldn't be expected to help you debug it. But by all means, tear it apart and rewrite it. If we all didn't do that, we wouldn't improve each others code - and we'd all close our minds to new ideas.
Finally, if you make changes that add functionality, or potentially improve performance or reliability, post your chanegs for discussion and review in the Scripts topic with an explaination of what you did.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#115627 - 2004-03-08 04:05 PM
Re: ScheduleTask()
|
Co
MM club member
Registered: 2000-11-20
Posts: 1341
Loc: NL
|
|
Top
|
|
|
|
#115628 - 2004-03-10 07:12 AM
Re: ScheduleTask()
|
attiahia
Hey THIS is FUN
Registered: 2000-03-27
Posts: 268
|
Based on posts I have read about ScheduleTask(), the following code should work but it doesn’t and I do not know why. I am trying to schedule this task on the PC where I am ruining the script. I am getting error function “1” incorrect function although I logged on with administrator account. Please help. Thank you. $name='test.job' $comp='bc301828' $date='TODAY' $time='now' $type='ONCE' $user='administrator' $pw='AbcN.16' $comment='test' $cmd='notepad' $jt= 'D:\jt.exe' scheduletask($name, $comp, $date, $time, $type, $cmd, $user, $pw, $comment, $jt) ? @SERROR :END Sleep 3 exit 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
$jtexe= 'D:\jt.exe'
$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
|
Top
|
|
|
|
#115629 - 2004-03-10 08:23 AM
Re: ScheduleTask()
|
Co
MM club member
Registered: 2000-11-20
Posts: 1341
Loc: NL
|
|
Top
|
|
|
|
#115630 - 2004-03-10 10:00 AM
Re: ScheduleTask()
|
attiahia
Hey THIS is FUN
Registered: 2000-03-27
Posts: 268
|
Thanks lot Co for advise, I already did this action but was giving the same error. (I even change Jt.exe location).
Maybe I am still missing some thing . Please help. thank you.
Note: OS is XP
|
Top
|
|
|
|
#115632 - 2004-03-10 08:39 PM
Re: ScheduleTask()
|
Co
MM club member
Registered: 2000-11-20
Posts: 1341
Loc: NL
|
Use the original UDF:
Code:
; 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
_________________________
Co
|
Top
|
|
|
|
#115633 - 2004-03-10 11:24 PM
Re: ScheduleTask()
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
Try this UDF modification to the end if the file to test it: Code:
; don't run the command ;Shell '%COMSPEC% /e:1024 /c '+$shellcmd+' >NUL 2>NUL' $ = RedirectOutput('jtcmd.bat') $shellcmd ? $ = RedirectOutput('')
This will place the complete JT command syntax into a BAT file that you can edit. Edit the file and review the syntax, making sure that commands don't run together (have proper spaces between them), are all on one line (turn line-wrap OFF), and maybe even review the syntax for correctness. If you download the zip file for my tsControl library, there's a JT doc file that better describes the functions and arguments of JT.
Finally, after validating the bat file, execute it and see if any other errors are reported. There may be a "JT.exe is not a recognized command" if it can't find the file. You may see other errors from JT.
This process will help you isolate whether the UDF is not functioning, if it is not properly generating JT syntax, or JT itself is failing. The UDF has been well tested, so - other than your (supposedly) minor modification, the only other errors could be introduced when you downloaded it. Some spaces may not be present, affecting the JT syntax generation or something similar. Until you can begin to narrow it down, you're shooting in the dark.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#115634 - 2004-03-13 09:57 AM
Re: ScheduleTask()
|
attiahia
Hey THIS is FUN
Registered: 2000-03-27
Posts: 268
|
Glenn
Thanks for the valuable advice. I was in sick live for the last 2 days. It is working from bat file while it doesn’t from the script. I will work on finding out the reason and update the post.
CitrixMan
You are right, domain or machine name should precede the user ide.
Thank you very much.
|
Top
|
|
|
|
#115635 - 2004-03-14 09:45 AM
Re: ScheduleTask()
|
attiahia
Hey THIS is FUN
Registered: 2000-03-27
Posts: 268
|
All what I hade to do is changing JT location and then it worked. Now I came across with other authorization problem, your help is appreciated. The function\jt will pick up the current existing user id if you omitted it; is there any way to do the same thing for password also?
Through an official request to access control group I have created a “service account”. Before modifying the login script to add this account automatically to the power user group on all the user workstations, I added it manually to my PC then (while I already logged on with my own user id attiahia) I run the script with the service account & its password. Job has created but does not execute. Should the service account have admin privilege?
Thank you for any help.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|