#27561 - 2002-08-22 05:30 PM
scheduletask() not working for regular user...
|
Rocco Capra
Hey THIS is FUN
   
Registered: 2002-04-01
Posts: 380
Loc: Mansfield Ohio
|
I have this running in a test login script. When I login to NT as a "Domain Admin" it runs fine. When I login as a "Domain User" it returns an errorcode of 1, but cannot tell where it is failing?!
Oh wait, If I try to add it manually as a "Domain User" and specify the admin user it won't let me do that.
So, '?' is... Is the user and password needed? to create and run the task? Uh, I just tested that and Yep you need it.
So, new '?'... Best way to get the user's ID and password for the task?
code:
BREAK ON
;IF Exist("%WINDIR%\Log-Off.txt") GOTO END ENDIF
;$RC = OPEN(1,"%WINDIR%\Log-Off.txt",5) ;$RC = WRITELINE(1,"Log-Off Task is installed.") ;$RC = CLOSE(1) IF NOT EXIST(("%WINDIR%\jt.exe")AND("%WINDIR%\shutdown.exe")) COPY @STARTDIR + "\_auxfiles\LogOff\*.exe" "%WINDIR%" ENDIF SLEEP 2 ? "[ Setting Task Scheduler Job ]" $taskname='Log-Off.job' $computer='@WKSTA' $date='08/22/2002' $time='1:32' $type='DAILY' $userid='admin' $userpw='pass' $comment='This task is to force a Log-Off every night On this PC.' $command='C:\winnt\shutdown.exe' $parameters=' /r /c' $RC = scheduletask($taskname,$computer,$date,$time,$type,$userid,$userpw,$comment,$command,$parameters) ? $RC GET $X :END ;========================================================== ;========================================================== function scheduletask($taskname, $computer, $date, $time, $type, $userid, $userpw, $comment, $command, $parameters) Dim $jtexe, $shellcmd, $retcode if $taskname='' ? 'Variable TASKNAME in function SCHEDULETASK is empty' exit 87 endif if $computer='' ? 'Variable COMPUTER in function SCHEDULETASK is empty' exit 87 endif if $date='' ? 'Variable DATE in function SCHEDULETASK is empty' exit 87 endif if $time='' ? 'Variable TIME in function SCHEDULETASK is empty' exit 87 endif if $type='' ? 'Variable TYPE in function SCHEDULETASK is empty' exit 87 endif if $userid='' ? 'Variable USERID in function SCHEDULETASK is empty' exit 87 endif if $userpw='' ? 'Variable USERPW in function SCHEDULETASK is empty' exit 87 endif if $comment='' ? 'Variable COMMENT in function SCHEDULETASK is empty' exit 87 endif if $command='' ? 'Variable COMMAND in function SCHEDULETASK is empty' exit 87 endif if not vartype($parameters) Dim $parameters $parameters='' endif ; this should point to your copy of jt.exe $jtexe='C:\winnt\jt.exe' ; delete a potentially existing task $shellcmd=$jtexe+' /SM \\'+$computer+' /SD '+$taskname shell '%COMSPEC% /e:1024 /c '+$shellcmd+" >NUL" if @ERROR > 0 $RC = Open(2,"\\MANFP1NT\Public\IT\_RoccoC\temp\log-off_nt.txt",5) $RC = WriteLine(2,@SERROR+@CRLF+@ERROR+@CRLF) $RC = Close(2) endif
; create a new task, save it, and force a run $shellcmd = $jtexe $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 $shellcmd = $shellcmd+ ' /SC '+$userid+' '+$userpw $shellcmd = $shellcmd+ ' /SJ ApplicationName="'+$command+'"' $shellcmd = $shellcmd+ ' Parameters="'+$parameters+'"' $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=0' $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+ ' /SM \\'+$computer $shellcmd = $shellcmd+ ' /SAJ '+$taskname $shellcmd = $shellcmd+ ' /SAC '+$taskname shell "%COMSPEC% /e:1024 /c "+$shellcmd+" >NUL" $scheduletask=@ERROR endfunction
Thanks,
Rocco
_________________________
I Love this board!!
--------------------
My DEV PC is running
KIX 4.22 WINXP Pro
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 837 anonymous users online.
|
|
|