#115639 - 2004-03-14 01:14 PM
Re: ScheduleTask()
|
attiahia
Hey THIS is FUN
Registered: 2000-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 - 2004-03-14 02:47 PM
Re: ScheduleTask()
|
Co
MM club member
Registered: 2000-11-20
Posts: 1341
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
|
|
|
|
#115642 - 2004-03-24 01:51 PM
Re: ScheduleTask()
|
attiahia
Hey THIS is FUN
Registered: 2000-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
|
|
|
|
#115645 - 2004-03-27 08:53 AM
Re: ScheduleTask()
|
attiahia
Hey THIS is FUN
Registered: 2000-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
|
|
|
|
#115651 - 2004-03-30 02:31 PM
Re: ScheduleTask()
|
attiahia
Hey THIS is FUN
Registered: 2000-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 - 2004-03-30 11:53 PM
Re: ScheduleTask()
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
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
|
|
|
|
#115654 - 2004-03-31 06:49 AM
Re: ScheduleTask()
|
attiahia
Hey THIS is FUN
Registered: 2000-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 - 2004-03-31 09:06 AM
Re: ScheduleTask()
|
attiahia
Hey THIS is FUN
Registered: 2000-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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 248 anonymous users online.
|
|
|