Page 1 of 1 1
Topic Options
#110531 - 2003-12-17 11:20 PM Unable to get Scheduled Task to run
ShaneEP Moderator Offline
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
#110532 - 2003-12-18 12:41 AM Re: Unable to get Scheduled Task to run
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
The use of %LOGONSERVER% requires a domain account to be used for the Task Scheduler. How do you provide the parameters to the ScheduleTask UDF? Please post the relevant code.
_________________________
There are two types of vessels, submarines and targets.

Top
#110533 - 2003-12-18 12:47 AM Re: Unable to get Scheduled Task to run
ShaneEP Moderator Offline
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
#110534 - 2003-12-18 12:50 AM Re: Unable to get Scheduled Task to run
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Maybe this is a false assumption...But when you run the task that points to a .bat as an admin account...The admin priviledges do get passed to other scripts that are launched from the .bat right?
Top
#110535 - 2003-12-18 12:54 AM Re: Unable to get Scheduled Task to run
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
I also tried changing the password for the account I am using thinking maybe it was kind of password length restriction or something...No cigar. I changed it to the same as my account, which works.
Top
#110536 - 2003-12-18 12:57 AM Re: Unable to get Scheduled Task to run
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Couple of things. Try to manually schedule the task. Try to have the batch file on the local computer. The batch file can then still call the patch install routine on the server. Do a simple batch file that just does a NET SEND to you to test the scheduling. I've never used the ATLOGON indicator, try removing it and just do the NOW as it might conflict with each other.
_________________________
There are two types of vessels, submarines and targets.

Top
#110537 - 2003-12-18 12:58 AM Re: Unable to get Scheduled Task to run
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
If it helps any...I get the same behavior if I go through the Windows GUI and creat the task manually. If I use a different account it doesnt do anything. As soon as I change it to the logged in account it works. Seems like more of a windows / task scheduler problem than a kix.
Top
#110538 - 2003-12-18 01:05 AM Re: Unable to get Scheduled Task to run
ShaneEP Moderator Offline
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
#110539 - 2003-12-18 01:10 AM Re: Unable to get Scheduled Task to run
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Also get the same result if the .bat script is copied to local drive.
Top
#110540 - 2003-12-18 01:16 AM Re: Unable to get Scheduled Task to run
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Then I'd say the %LOGONSERVER% is not getting translated correctly. Put a
Code:

echo %LOGONSERVER% >%TEMP%\ts_echo.txt


into the batch file. That'll show you to what the environmentvariable gets translated to. BTW, the %LOGONSERVER% will get translated to the server that authenticates the account used to run the scheduled task.
_________________________
There are two types of vessels, submarines and targets.

Top
#110541 - 2003-12-18 01:22 AM Re: Unable to get Scheduled Task to run
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
echo "%LOGONSERVER%" >F:\ts_echo.txt

results in a text file containing only the ""

I had to change it from %temp% to F:\ because apparently the %temp% isnt getting defined either. Do you have any idea what would cause this?

Top
#110542 - 2003-12-18 02:03 AM Re: Unable to get Scheduled Task to run
ShaneEP Moderator Offline
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
#110543 - 2003-12-18 02:12 AM Re: Unable to get Scheduled Task to run
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
I've found some stuff on the Windows & .NET Magazine website which essentially states that user environment variables are not available in scheduled tasks. Thus, both %LOGONSERVER% and %TEMP% would fail. Systemwise environment variables should be available. %TEMP% might be available and point to the system temp directory.

A way around this might be to schedule a task that calls %COMSPEC% with a parameter indicating the batch file. This might trigger the initialization of the user environment variables.

Okay, found another reference in a newsgroups, see Environment Variable in Schedule Task .

So, essentially, don't use user environment variables. I'll put a disclaimer into the UDF to reflect this.


Edited by sealeopard (2003-12-18 02:21 AM)
_________________________
There are two types of vessels, submarines and targets.

Top
#110544 - 2003-12-18 02:46 AM Re: Unable to get Scheduled Task to run
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
That blows...Oh well. Have yet to find a way to get the %logonserver%. How accurate is the @LServer macro on NT4/2K/XP clients?

Workaround I am going with for now. Copied the msupdater_install.kix script to same share that the .bat was previously located. Renamed the .kix file to kixtart.kix and also copied in wkix32.exe. This way I can set the task to run \\server\share\wkix32.exe. This launches the main isntall script and then refers to the @LServer everywhere I used to use %logonserver%. The only problem is that now the script and wkix32.exe is coming from a share here over the WAN everytime a user runs it (about 260kb). I will do some testing over a slow link and see if it causes any issues.

Top
#110545 - 2003-12-18 02:47 AM Re: Unable to get Scheduled Task to run
ShaneEP Moderator Offline
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
#110546 - 2003-12-18 03:07 AM Re: Unable to get Scheduled Task to run
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
@LSERVER might not be available either but it should be easy to test this.
_________________________
There are two types of vessels, submarines and targets.

Top
#110547 - 2003-12-18 03:51 PM Re: Unable to get Scheduled Task to run
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
@LServer seems to work.

Do you schedule tasks across your WAN? How do you do it without the updates having to go across the WAN whenever an update is run? Especially is it is scheuled in the middle of night when noone is logged on. Im guessing then @LServer wouldnt be available. Would @IPAddress0? Maybe I can make an .ini with all the locations listed and which server to use depending on their IP.

Top
#110548 - 2003-12-18 04:01 PM Re: Unable to get Scheduled Task to run
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
I just have a LAN with 100MBit to desktops and 1GBit to servers fully switched with one central admin share for updates/installs.

I normally run updates/installs during the night as we keep our computers running 24/7 due to number-crunching routines run on various machines.

@LSERVER and @IPADDRESS0 should be available in the client script as it does run under a user's context. @LSERVER should contain the server that authenticated the user when the scheduled task was started.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
2 registered (morganw, mole) and 414 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.071 seconds in which 0.022 seconds were spent on a total of 12 queries. Zlib compression enabled.

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