Page 1 of 1 1
Topic Options
#27561 - 2002-08-22 05:30 PM scheduletask() not working for regular user...
Rocco Capra Offline
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
#27562 - 2002-08-22 05:32 PM Re: scheduletask() not working for regular user...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
bestway?
create a spooky user and password.
or use system.
_________________________
!

download KiXnet

Top
#27563 - 2002-08-22 05:37 PM Re: scheduletask() not working for regular user...
Rocco Capra Offline
Hey THIS is FUN
*****

Registered: 2002-04-01
Posts: 380
Loc: Mansfield Ohio
System would be great! do you know if it needs a password off hand??
_________________________
I Love this board!! -------------------- My DEV PC is running KIX 4.22 WINXP Pro

Top
#27564 - 2002-08-22 05:39 PM Re: scheduletask() not working for regular user...
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The user that is running must provide a userid and password for the Task Scheduler. Tasks cannot run without a valid userid and password.

You can try it in the Task Scheudler GUI, too, it won't let you do anything without id/pw.

Yes, SYSTEM has it's own password.

I've created a special userid/password just for the Task Scheduler, in my case it's a domain admin account which will give it automatically local admin rights.

[ 22. August 2002, 17:42: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#27565 - 2002-08-22 05:47 PM Re: scheduletask() not working for regular user...
Rocco Capra Offline
Hey THIS is FUN
*****

Registered: 2002-04-01
Posts: 380
Loc: Mansfield Ohio
I am trying to pump in a Domain Admin user to it but since the user that is logging on is not an admin I get an error return of 1. Also if I try to do GUI the error I get is Access Denied.

Logged in as a regular user I tried to use the domain admin and system and even the local admin account and get the same access denied error each time.

I'm starting to feel like Charlie Brown.
_________________________
I Love this board!! -------------------- My DEV PC is running KIX 4.22 WINXP Pro

Top
#27566 - 2002-08-22 06:01 PM Re: scheduletask() not working for regular user...
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The 'Access denied' message means that the user doesn't have the right to schedule a task (using the provided credentials). Check whether the user can create a task for itself.
_________________________
There are two types of vessels, submarines and targets.

Top
#27567 - 2002-08-22 06:09 PM Re: scheduletask() not working for regular user...
Rocco Capra Offline
Hey THIS is FUN
*****

Registered: 2002-04-01
Posts: 380
Loc: Mansfield Ohio
Yes. He can create one for himself.
_________________________
I Love this board!! -------------------- My DEV PC is running KIX 4.22 WINXP Pro

Top
Page 1 of 1 1


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

Who's Online
0 registered and 884 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.055 seconds in which 0.024 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