Page 1 of 3 123>
Topic Options
#115616 - 04/03/06 01:53 PM ScheduleTask()
attiahia Offline
Hey THIS is FUN

Registered: 00/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 - 04/03/06 03:38 PM Re: ScheduleTask()
Kdyer Offline
KiX Supporter
*****

Registered: 01/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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#115618 - 04/03/06 04:07 PM Re: ScheduleTask()
Sealeopard Offline
KiX Master
*****

Registered: 01/04/25
Posts: 11161
Loc: Boston, MA, USA
I do not recommed making changes to the UDF. There's a reason why the UDF looks in different directories for the JT.EXE executable.

Secondly, I'm not going to support UDFs that I wrote and where somebody else made unauthorized chanegs to it. You can always request changes/improvements.

Quote:


If I am sure of JT.exe location, can I replace the following part of the function:




You can alwasy provide the path to your copy of JT.EXE as part of the UDF parameters.

Is it not working for you?


Edited by sealeopard (04/03/06 04:10 PM)
_________________________
There are two types of vessels, submarines and targets.

Top
#115619 - 04/03/07 12:44 AM Re: ScheduleTask()
Co Offline
MM club member
***

Registered: 00/11/20
Posts: 1338
Loc: NL
Jens,

It works for me since a long time. And I agree with you...
_________________________
Co


Top
#115620 - 04/03/07 07:17 AM Re: ScheduleTask()
attiahia Offline
Hey THIS is FUN

Registered: 00/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
#115621 - 04/03/07 10:34 AM Re: ScheduleTask()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 01/06/05
Posts: 22294
Loc: Claremore, OK
that's weird.
how many newbie programmers you think go and mod the libraries done by MS?
I know, they are cryptic as the code I produce, but anyway.

the base line is, if you have something proven working, don't mess with it.
if your code does fail, don't mess with it. trust it.

you are just asking for problems if you go and tweak the UDFs.
well, most of them.

there is still some UDFs (even by moderators) that don't qualify as UDFs as they require you to tweak them to make them work.
won't name anybody here as have personally complained to them multiple times already.

you were already told how to call the UDF with specified path.
you can use your curdir (which I never ever use btw) there.
after the function-call, you can easily put if @error "error found" endif line.

it's so simple I don't see any reason but stubberness forcing you to insist tweaking and braking the code.
_________________________
!

download KiXnet

Top
#115622 - 04/03/07 03:05 PM Re: ScheduleTask()
Sealeopard Offline
KiX Master
*****

Registered: 01/04/25
Posts: 11161
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
#115623 - 04/03/07 03:37 PM Re: ScheduleTask()
Co Offline
MM club member
***

Registered: 00/11/20
Posts: 1338
Loc: NL
Quote:

...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.





@attiahia

First: Like Jens has said "You're welcome to modify UDFs and scripts on your own". That isn't the problem. If it is we shouldn't post our scripts/UDFs in this Forum.

Please tell us when you have changed an UDF and tell us what you have changed. (like you did ). When we know this we can pay attention to it...

If you have changed a lot you can give the the UDF another name like ScheduleTask2().

Good luck...





Edited by Co (04/03/07 08:01 PM)
_________________________
Co


Top
#115624 - 04/03/07 04:23 PM Re: ScheduleTask()
Glenn Barnas Moderator Offline
KiX Supporter
*****

Registered: 03/01/28
Posts: 4205
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! \:D

Top
#115625 - 04/03/07 09:20 PM Re: ScheduleTask()
Co Offline
MM club member
***

Registered: 00/11/20
Posts: 1338
Loc: NL
Quote:

Well, Lonk, for some of us, reading, understanding, and modifying code from others is just another way to learn....




Well said... Since I'm not a programmer I have used and still use this tactics to become a better scripter/programmer. I also use it to compare my own code with someone else his code. Sometimes you are in the wrong track. Comparing codes can save lots of time .

Still I agree with Jens. Since lots of UDF's are containing Jens's name we can not expect him to support all those UDFs. surely when they are modified..

Quote:

...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.




This is the way to discuss changes.... When changes are accepted version numbers must change too.. just like in the real world


Edited by Co (04/03/07 09:27 PM)
_________________________
Co


Top
#115626 - 04/03/08 06:28 AM Re: ScheduleTask()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 01/06/05
Posts: 22294
Loc: Claremore, OK
well well...
who has talked about providing OS code?
talking about basic coding libraries that come with normal programming tools.
and I know, ppl tend to mod these too, but surely NOT ONE NEWBIE even looks in them as they are pure hebrew to them.

sure, it's different with scripting as basically it is lots simpler.
sure, you can go and screw things up to learn.

but if you want to make working code, you observe and leave the original source untouched!
that's the basic first rule, if you are to do your own stuff, do it but modding original code does not make it yours.
heh, basic way would be to mod just the author tag.

what comes to inventing...
you surely kill invention if you go and learn everything by studying from other ppl's codes.
this way, your mind becomes like theirs and your brains became tracked.
_________________________
!

download KiXnet

Top
#115627 - 04/03/08 04:05 PM Re: ScheduleTask()
Co Offline
MM club member
***

Registered: 00/11/20
Posts: 1338
Loc: NL
Quote:

...your mind becomes like theirs...




Ohooh!! lets hope people don't use your posts to much
_________________________
Co


Top
#115628 - 04/03/10 07:12 AM Re: ScheduleTask()
attiahia Offline
Hey THIS is FUN

Registered: 00/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 - 04/03/10 08:23 AM Re: ScheduleTask()
Co Offline
MM club member
***

Registered: 00/11/20
Posts: 1338
Loc: NL
Strange...

When I compare your script with one of my own. The only thing which is different is the name of the task. Leave .job, just call it test...

http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB2&Number=110124&Forum=UBB2&Words=array&Match=Entire%20Phrase&Searchpage=1&Limit=25&Old=6months&Main=109672&Search=true#Post110124
_________________________
Co


Top
#115630 - 04/03/10 10:00 AM Re: ScheduleTask()
attiahia Offline
Hey THIS is FUN

Registered: 00/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
#115631 - 04/03/10 08:27 PM Re: ScheduleTask()
ShaneEP Moderator Offline
MM club member
*****

Registered: 02/11/29
Posts: 1988
Loc: Tulsa, OK
Do you have to maybe put a machine or domain in front the username? I know from my own experiences that if the authentication fails...It will return the error you specified. I struggled with it for hours before I realised I had simply mistyped a password.
Top
#115632 - 04/03/10 08:39 PM Re: ScheduleTask()
Co Offline
MM club member
***

Registered: 00/11/20
Posts: 1338
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 - 04/03/10 11:24 PM Re: ScheduleTask()
Glenn Barnas Moderator Offline
KiX Supporter
*****

Registered: 03/01/28
Posts: 4205
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! \:D

Top
#115634 - 04/03/13 09:57 AM Re: ScheduleTask()
attiahia Offline
Hey THIS is FUN

Registered: 00/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 - 04/03/14 09:45 AM Re: ScheduleTask()
attiahia Offline
Hey THIS is FUN

Registered: 00/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
Page 1 of 3 123>


Moderator:  Jochen, Allen, Radimus, Chris S., Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 131 anonymous users online.
Newest Members
OKCPCS, mprell, Dad24Lads, Cutebear, kstieers
17434 Registered Users

Generated in 0.041 seconds in which 0.01 seconds were spent on a total of 13 queries. Zlib compression enabled.

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