#110531 - 2003-12-17 11:20 PM
Unable to get Scheduled Task to run
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
hello again...
I am having some trouble getting a task created with the ScheduleTask UDF to run correctly. I noticed from some previous posts that the task gets run in the background if a different account is specified for it to run under. But I never see any sign of the task ever running (example...reg keys that should be added are not there). Below is the batch file that is calling a .kix file.
I know its not a problem with either of the scripts since when I change the task to run as myself (the user logged on) so that it doesnt run it the background...It runs fine. If I change it to run as a different user then it doesnt run. The user I am changing it to has domain admin rights so I know it isnt a security issue.
Anyone have any ideas? I can post the .kix script as well is necessary.
Code:
@echo off
%logonserver%\netlogon\wkix32.exe %logonserver%\netlogon\MSUpdater_Install.kix
|
Top
|
|
|
|
#110533 - 2003-12-18 12:47 AM
Re: Unable to get Scheduled Task to run
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
This is the code I am using to schedule the task...The task seems to get created correctly (error 0). I can see the task on the remote machine. But when I log off or even if I right-click the task and select Run it seems to do nothing. If I edit the properties of the task and change it to my login and try running it again it seems to work.
Code:
Break On
Dim $null,$ini,$lf,$patches,$patch,$computers,$computer,$patchneeded,$scheduled
$null=SETOPTION('Explicit','on')
$null=SETOPTION('NoVarsInStrings','on')
$null=SETOPTION('WrapAtEOL','on')
$ini = "\\server\share\Status\patch_status.ini"
$lf = chr(10)
$patches = Split (ReadProfileString ($ini,'',''),$lf)
For Each $patch in $patches
If $patch
$computers = Split (ReadProfileString ($ini,$patch,''),$lf)
For Each $computer in $computers
If $computer
$patchneeded = ReadProfileString ($ini,$patch,$computer)
If $patchneeded = "1" and $computer = "testcomputer" and $scheduled <> "1"
? 'Scheduling MS Update task for '+$computer
$null=scheduletask('MS_Updates', $computer, 'Today', 'Now', 'AtLogon',
'\\server\share\MSUpdater_Install.bat', '', 'DOMAIN\account',
'password', 'MS Updates For November Of 2003')
? 'Error '+@ERROR+' - '+@SERROR
If @Error = 0
$scheduled = "1"
$null = WriteProfileString ($ini,"SCHEDULED",$computer,"1")
Endif
Endif
Endif
Next
Endif
Next
get $null
; ------------------------------------------
; Schedule A Remote Task Using Task Scheduler
; ------------------------------------------
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 $type='' or $cmd='' or $date='' or $time=''
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'
$shellcmd = $shellcmd+ ' 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
Edited by CitrixMan (2003-12-18 12:51 AM)
|
Top
|
|
|
|
#110538 - 2003-12-18 01:05 AM
Re: Unable to get Scheduled Task to run
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
ah-ha...Put the net send in the .bat and do indeed get a message when I run the task. So for some reason the .bat isnt able to start the .kix script. The .bat is pretty simple...
Code:
@echo off
net send testcomputer scheduled batch script has begun
%logonserver%\netlogon\wkix32.exe %logonserver%\netlogon\MSUpdater_Install.kix
Also added the following line to the beginning of the .kix script that is called from the .bat. But I never see this second message.
Code:
shell '%comspec% /c net send testcomputer The Scheduled Kix Script Has Begun'
|
Top
|
|
|
|
#110542 - 2003-12-18 02:03 AM
Re: Unable to get Scheduled Task to run
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Not so sure the %logonserver% is going to be possible when using a scheduled task. I was wrong about the %temp% not getting set...It was set just to the other accounts profile. A number of env variable get set...When I do a set > F:\variables.txt I get...
Quote:
ALLUSERSPROFILE=F:\Documents and Settings\All Users CommonProgramFiles=F:\Program Files\Common Files COMPUTERNAME=computername ComSpec=F:\WINNT\system32\cmd.exe NUMBER_OF_PROCESSORS=1 OS=Windows_NT Os2LibPath=F:\WINNT\system32\os2\dll; Path=F:\WINNT\system32;F:\WINNT;F:\WINNT\System32\Wbem;C:\PROGRA~1\SYMANTEC\PCANYW~1\; PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH PROCESSOR_ARCHITECTURE=x86 PROCESSOR_IDENTIFIER=x86 Family 6 Model 8 Stepping 3, GenuineIntel PROCESSOR_LEVEL=6 PROCESSOR_REVISION=0803 ProgramFiles=F:\Program Files PROMPT=$P$G SystemDrive=F: SystemRoot=F:\WINNT TEMP=F:\DOCUME~1\MSUpdate\LOCALS~1\Temp TMP=F:\DOCUME~1\MSUpdate\LOCALS~1\Temp USERDNSDOMAIN=domain.com USERDOMAIN=DOMAIN USERNAME=MSUpdate USERPROFILE=F:\Documents and Settings\MSUpdate windir=F:\WINNT
As you can see...No logonserver. I also tried passing the %logonserver% as a variable to the first .bat. Task Scheduler wont expand it out...The variable is literally "%logonserver" in the .bat.
This sucks...
|
Top
|
|
|
|
#110545 - 2003-12-18 02:47 AM
Re: Unable to get Scheduled Task to run
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Thanks for all of the help by the way...I never would have never thought that the %logonserver% wasnt being defined.
Edited by CitrixMan (2003-12-18 03:49 PM)
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 515 anonymous users online.
|
|
|