Page 2 of 3 <123>
Topic Options
#115636 - 04/03/14 10:52 AM Re: ScheduleTask()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 01/06/05
Posts: 22294
Loc: Claremore, OK
if it is there, it already has rights to add scheduled jobs.
you should check what the error is.
_________________________
!

download KiXnet

Top
#115637 - 04/03/14 11:04 AM Re: ScheduleTask()
Co Offline
MM club member
***

Registered: 00/11/20
Posts: 1338
Loc: NL
Yeah, but maybe no permissions to execute them...

Edited by Co (04/03/14 11:05 AM)
_________________________
Co


Top
#115638 - 04/03/14 11:32 AM Re: ScheduleTask()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 01/06/05
Posts: 22294
Loc: Claremore, OK
well...
haven't herd there is separate scheduler permissions for exec and add and maybe even delete.
but, the file rights might be worth checking.
once again, the error recorded would simply clear the clouds and remove the need for quessing.
_________________________
!

download KiXnet

Top
#115639 - 04/03/14 01:14 PM Re: ScheduleTask()
attiahia Offline
Hey THIS is FUN

Registered: 00/03/27
Posts: 268
Error is: [FAIL ] ITaskScheduler::AddWorkItemn hr=0x80070005

As I mentioned, job created but it does not execute at the specified time. Furthermore, when I check the job setting in GUI schedule task I found the Run as setting is still attiahia which is the user id I used to login to the machine.

Below is the bat file were redirect output (as Glenn helpful advice)

D:\>D:\jt.exe /SC "Domain Name\Service Account" "Service.123" /SM \\bc301828 /SJ ApplicationName="notepad" Parameters="d:\test.txt" WorkingDirectory="C:\WINDOWS" Comment="cool!" Creator=" Service Account " Priority=Normal MaxRunTime=3600000 DontStartIfOnBatteries=0 KillIfGoingOnBatteries=0 RunOnlyIfLoggedOn=0 SystemRequired=0 DeleteWhenDone=1 Suspend=0 StartOnlyIfIdle=0 KillOnIdleEnd=0 RestartOnIdleResume=0 Hidden=0 TaskFlags=0 /CTJ StartDate=TODAY StartTime=14:46 HasEndDate=0 KillAtDuration=0 Disabled=0 Type=ONCE /SAJ "Exam.job"

[TRACE] Setting account information
[TRACE] Setting target computer to '\\bc301828'
[TRACE] Setting job's properties
[TRACE] Created trigger 0
[TRACE] Adding job 'Exam.job'
[FAIL ] ITaskScheduler::AddWorkItemn hr=0x80070005

Thank you

Top
#115640 - 04/03/14 02:47 PM Re: ScheduleTask()
Co Offline
MM club member
***

Registered: 00/11/20
Posts: 1338
Loc: NL
I think you don't start the job with the service account but with the logged in useraccount... You have to fill in username and password

you can test this by giving your own account admin credentials... When the job starts this time it means you don't use the service account.

Still my opinion is to use the original UDF. Give it a try. I have used it a lot of times and never had problems with it...

Code:
Break On


$name='sync_scripts_dir'
$comp='comp1'
$date='TODAY'
$time='17:30'
$type='ONCE'
$cmd='\\comp1\Scripts\kix\sync_scripts_dir.exe'
;$prms=''
$user='admin'
$pw='adminpw'
;$comment='test'
;$typeargs=''
;$jt= 'c:\jt.exe'
scheduletask($name, $comp, $date, $time, $type, $cmd, $user, $pw)
? 'Error '+@ERROR+' - '+@SERROR

Exit


;FUNCTION ScheduleTask
;
;ACTION Schedules a task on any computer using the Task Scheduler
;
;AUTHOR Jens Meyer (sealeopard@usa.net)
;
;VERSION 1.41 (corrected typos in the date checker)
; 1.4 (added support for both MM/DD/YYY and YYYY/MM/DD date formats
; 1.3 (made username/password/comment optional parameters, changed parameter order, added
; optional parameter for JT.EXE location, checks %PATH% for presence of JT.EXE)
; 1.2 (removed error code trigger for deleting non-existing tasks, changed order of
; parameters that create task, updated header with regards to quote usage, added
; optional typearguments)
; 1.1 (added error codes, streamlined code)
; 1.0
;
;DATE CREATED 2001/12/04
;
;DATE MODIFIED 2004/01/06
;
;KIXTART 4.12+
;
;SYNTAX SCHEDULETASK($NAME,$COMP,$DATE,$TIME,$TYPE,$CMD [,$PRMS,$USER,$PW,$COMMENT,TYPEARGS,JT])
;
;PARAMETERS NAME
; name of the task
;
; COMP
; computername on which the task is to be run, computer must have the Task Scheduler installed
;
; DATE
; date on which to run the task (MM/DD/YYYY, YYYY/MM/DD, or TODAY)
;
; TIME
; time on which to run the task (H:M or NOW) with NOW indicating 60 seconds in the future
;
; TYPE
; trigger types (DAILY n | WEEKLY n, | MONTHLYDATE , | MONTHLYDOW n,,months |
; ONCE | ONIDLE | ATSTARTUP | ATLOGON)
;
; CMD
; the command to be executed by the task scheduler, cannot contain the quote character "
;
; USER
; userid under which to run the task (can be any valid local or domain user). If no userid
; is provided then the current userid is being used
;
; PW
; password for the userid
;
; PRMS
; optional parameters that are provided to the command, cannot contain the quote character "
;
; COMMENT
; comment field with information about task, cannot contain the quote character "
;
; TYPEARGS
; Optional parameter for trigger types, see jt /? ctj for details
;
; JT
; optional string denoting the location of JT.EXE, by default the UDF checks for JT.EXE
; in @STARTDIR, @SCRIPTDIR, @CURDIR, and %PATH%. @SCRIPTDIR will point to the location of the file
; containing the ScheduleTask UDF which does not necessarily need to be in the same directory
; as the actual script.
;
;RETURNS 0 if successful, otherwise error code
;
;REMARKS Requires the file JT.EXE, which is part of the Microsoft Windows 2000 Resource Kit Supplement
; and can be downloaded at ftp://ftp.microsoft.com/reskit/win2000/jt.zip
; Best used to schedule batch files due to problems with double quote usage in some of the JT.EXE parameters.
; Administrative privileges on the remote computer are required in order to schedule a task on the remote computer
; User environment variables like %USERNAME% or %LOGONSERVER% are not available in the scheduled tasks. System-wide
; environmentvariables like %COMSPEC% or %WINDIR% can be used, however.
;
;DEPENDENCIES 'Task Scheduler' service, can be installed via IE5.5 'Offline Browsing Pack' component under Windows NT 4.0
;
;EXAMPLE $name='demo.job'
; $comp='SERVER'
; $date='TODAY'
; $time='NOW'
; $type='ONCE'
; $cmd='notepad'
; $prms='%TEMP%\test.txt'
; $user='administrator'
; $pw='adminpassword'
; $comment='cool!'
; $typeargs=''
; $rc=scheduletask($name,$comp,$date,$time,$type,$cmd,$prms,$user,$pw,$comment,$typeargs,$jt)
;
;KIXTART BBS http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB12&Number=81907
;
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

select
case $date='TODAY'
; valid format
case len($date)<>10
exit 87
case substr($date,3,1)='/'
; valid format
case substr($date,5,1)='/'
; reformat date
$date=split($date,'/')
$date=$date[1]+'/'+$date[2]+'/'+$date[0]
case 1
exit 87
endselect

; 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
#115641 - 04/03/14 03:21 PM Re: ScheduleTask()
Sealeopard Offline
KiX Master
*****

Registered: 01/04/25
Posts: 11161
Loc: Boston, MA, USA
Yes, you have to supply both[/b[] username and password, otherwise the account that runs the ScheduleTask() script will be used. There is no way that the password for a username can be retreived automatically in any way, unless you crack the passwords hash value or brute-force generate the password.
_________________________
There are two types of vessels, submarines and targets.

Top
#115642 - 04/03/24 01:51 PM Re: ScheduleTask()
attiahia Offline
Hey THIS is FUN

Registered: 00/03/27
Posts: 268
Lady & Gentlemen
I have received a great support from Glenn and you and I can say 80 % of the problem has been solved.

The job has been scheduled under the service account but here is the strange different.

When I schedule the task under my account which I used to logon, the task executed at the specified time and NOTEPAD.exe appear to me but when I logon with my account and schedule the task with the service account it still work & executed at the specified time but NOTEPAD.exe does not appear to me.
In the task statues I can see that task is running and NOTEPAD processor appear within windows task manager\active processors.

I have tried to add Interactive parameter but also did not work. Please help. Thank you.


D:\jt.exe /SC "Domain\ServiceAccount" "password" /SM \\bc301828 /SJ ApplicationName="NOTEPAD" Parameters="C:\WINDOWS\NOTEPAD" WorkingDirectory="C:\WINDOWS\NOTEPAD" Comment=" Service Account Test" Creator="Domain\attiahia" Priority=Normal MaxRunTime=3600000 DontStartIfOnBatteries=0 KillIfGoingOnBatteries=0 RunOnlyIfLoggedOn=0 SystemRequired=0 DeleteWhenDone=1 Suspend=0 StartOnlyIfIdle=0 KillOnIdleEnd=0 RestartOnIdleResume=0 Hidden=0 TaskFlags=0 /CTJ StartDate=TODAY StartTime=15:23 HasEndDate=0 KillAtDuration=0 Disabled=0 Type=ONCE /SAJ "JT1a.job"

Top
#115643 - 04/03/24 03:16 PM Re: ScheduleTask()
Glenn Barnas Moderator Offline
KiX Supporter
*****

Registered: 03/01/28
Posts: 4194
Loc: New Jersey
I'm thinking that this is normal and expected behavior. An "interactive" event would only appear/interact with the event owner. Appearing on any other users desktop would be a potential (and possibly severe) security violation. Imagine if you scheduled (via an admin account) the user manager for domains to open interactively. If "Joe Schmoe" was logged in, he would be able to create any level of user id or group. An extreme idea, but it illustrates the point of why this would not be possible.

Glenn
_________________________
Visit the Inno-Tech web site for Kix tools/UDFs
Actually I am a Rocket Scientist! \:D

Top
#115644 - 04/03/24 04:56 PM Re: ScheduleTask()
Sealeopard Offline
KiX Master
*****

Registered: 01/04/25
Posts: 11161
Loc: Boston, MA, USA
Yes, that is expected and correct behavior. You can only interact with tasks scheduled under the same account that is logged in interactively to the computer.
_________________________
There are two types of vessels, submarines and targets.

Top
#115645 - 04/03/27 08:53 AM Re: ScheduleTask()
attiahia Offline
Hey THIS is FUN

Registered: 00/03/27
Posts: 268
This is not fair from JT and I am still hope that there is a trick, solution or alternative for this situation.
All what I need is to schedule a job that presenting employees with a power point slides at specific time.
your help is appreciated. Thank you.

Top
#115646 - 04/03/27 12:11 PM Re: ScheduleTask()
Co Offline
MM club member
***

Registered: 00/11/20
Posts: 1338
Loc: NL
It isn't JT it is the Task Scheduler Service...
_________________________
Co


Top
#115647 - 04/03/27 09:51 PM Re: ScheduleTask()
ShaneEP Moderator Offline
MM club member
*****

Registered: 02/11/29
Posts: 1984
Loc: Tulsa, OK
If you are only wanting to show a PPT slide at a specific time then why do you need to schedule it with an admin account? Why dont you just let it run under the user thats logged in?
Top
#115648 - 04/03/28 12:04 AM Re: ScheduleTask()
Sealeopard Offline
KiX Master
*****

Registered: 01/04/25
Posts: 11161
Loc: Boston, MA, USA
What's up with showing the PPT slide anyway while a user is working? I'd find that annoying and intrusive.

Also, the described behavior exists for (valid) security reasons.


Edited by sealeopard (04/03/28 12:05 AM)
_________________________
There are two types of vessels, submarines and targets.

Top
#115649 - 04/03/28 01:02 AM Re: ScheduleTask()
Co Offline
MM club member
***

Registered: 00/11/20
Posts: 1338
Loc: NL
...Or show it when a user turns his computer on. Use your loginscript to start the presentation. You don't disturb your users yet while they are working...

Edited by Co (04/03/28 10:59 AM)
_________________________
Co


Top
#115650 - 04/03/28 03:27 PM Re: ScheduleTask()
Sealeopard Offline
KiX Master
*****

Registered: 01/04/25
Posts: 11161
Loc: Boston, MA, USA
Actually, my and many other user's fiurst thought would be that there's a virus/worm/??? loose on my computer if such events happen that were not specifcally initiated by myself. I'd also start building a huge distrust toward the IT department as thay seem to have the ability to do things to my computer while I'm working on it. Remember, not everybody is IT-savy and you should evaluate how a standard user who's able to use Word but doesn't understand much else will see this.
_________________________
There are two types of vessels, submarines and targets.

Top
#115651 - 04/03/30 02:31 PM Re: ScheduleTask()
attiahia Offline
Hey THIS is FUN

Registered: 00/03/27
Posts: 268
Shane:
This what I was doing but it is not practical because the PPS slide appear to the user when he login but since most of our employees keep their
Workstations only locked off without logoff & logon for long time (can be a week), I found that I need to schedule executing this PPS slide on their BC’s.
The group policy on our main domain does not force logoff & logon and it is very difficult for me to ask for changing this policy.

CO:
If I placed the slide\script on the computer shutdown, no one will see it because they (if they decide to turn off the computer after long time) will simply Ctrl + Alt + Del and select shutdown and leave the office.

Jens:
It is a 20 seconds slide and we want to schedule it to appear to the employees every couple of days.
They are about 12 slides, each one show a success story for one of our employees who added value to the company.


Now,
I have faced another problem with JT and please do not tell me it is expected behavior:

All what I want to do is to set the EndDate parameter for the task.
The following code worked successfully under my account that I used to login but it did not when I login with my account and use the service account to schedule the task.

D:\jt.exe /SC "Domain Name\service account" "password.123" /SM \\bc301828 /SJ ApplicationName="Ping1" Parameters="C:\WINDOWS\Ping1" WorkingDirectory="C:\WINDOWS\Ping1" Comment="hhhhhh" Creator="domain name\attiahia" Priority=Normal MaxRunTime=3600000 DontStartIfOnBatteries=0 KillIfGoingOnBatteries=0 RunOnlyIfLoggedOn=0 SystemRequired=0 DeleteWhenDone=1 Suspend=0 StartOnlyIfIdle=0 KillOnIdleEnd=0 RestartOnIdleResume=0 Hidden=0 TaskFlags=0
/CTJ StartDate=03/30/2004 EndDate=04/05/2004 StartTime=11:03 HasEndDate=1
KillAtDuration=0 Disabled=0
Type=Daily /SAJ "Task1.job"

[TRACE] Setting account information
[TRACE] Setting target computer to '\\bc301828'
[TRACE] Setting job's properties
[TRACE] Created trigger 0
[TRACE] Setting properties on trigger 0
[TRACE] Adding job 'Task1.job'
[FAIL ] ITaskScheduler::AddWorkItemn hr=0x80070005


so when I keep the same code but with replacing the service account with my account that I am currently logged in with , it will work. Please help.

I have tried to use /STJ EndDate=04/05/2004 but also did not work.

Top
#115652 - 04/03/30 11:53 PM Re: ScheduleTask()
ShaneEP Moderator Offline
MM club member
*****

Registered: 02/11/29
Posts: 1984
Loc: Tulsa, OK
Quote:

Shane:
This what I was doing but it is not practical because the PPS slide appear to the user when he login but since most of our employees keep their
Workstations only locked off without logoff & logon for long time (can be a week), I found that I need to schedule executing this PPS slide on their BC’s.
The group policy on our main domain does not force logoff & logon and it is very difficult for me to ask for changing this policy.




I didnt mean to run it when the user logs in...I meant to schedule it so that it runs as the user that is logged in. Im not sure if there is a way to make it default to the currently logged in person or not. Just an idea.

Top
#115653 - 04/03/31 05:59 AM Re: ScheduleTask()
Sealeopard Offline
KiX Master
*****

Registered: 01/04/25
Posts: 11161
Loc: Boston, MA, USA
By not providing username/password the task will run under the credential of the user that called JT.EXE

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

Top
#115654 - 04/03/31 06:49 AM Re: ScheduleTask()
attiahia Offline
Hey THIS is FUN

Registered: 00/03/27
Posts: 268
Jens
As you can see in the code and as I mentioned that I am providing the user name (service account) and password and the task scheduled & executed successfully. The problem is that once I add EndDate parameter to the same code it stop working and generate error code “[FAIL ] ITaskScheduler::AddWorkItemn hr=0x80070005”.

What I need is to specify EndDate for the task. Thank you very much.

Top
#115655 - 04/03/31 09:06 AM Re: ScheduleTask()
attiahia Offline
Hey THIS is FUN

Registered: 00/03/27
Posts: 268
I have just tried many time to run the command without providing login id & password because I thought in such case the current credential will be used (as you mentioned) to schedule the task.

I found it is scheduling the task and in the GUI you can see that the task scheduled under the current credential but at the specific time the task will not be executed. I am getting error message
[TRACE] Setting account information
[TRACE] Setting job's properties
[TRACE] Created trigger 0
[TRACE] Adding job 'Aramco2K.job'
[FAIL ] ITaskScheduler::AddWorkItemn hr=0x80041310

Top
Page 2 of 3 <123>


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

Who's Online
0 registered and 104 anonymous users online.
Newest Members
KristopherMallor, B1GHawkeyes, GeoHamm, register, Marcus_Dunne
17398 Registered Users

Generated in 0.081 seconds in which 0.014 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