Rocco Capra
(Hey THIS is FUN)
2003-03-07 03:21 PM
scheduletask() error with 'Interactive'...

All (or Jens),

I try to use the 'Interactive' option on JT.exe and get the following output...
code:
[ Setting Task Scheduler Job ]
[TRACE] Created trigger 0
[TRACE] Setting account information
[TRACE] Setting job's properties
[ERROR] Expected job property name but found token 'Interactive'
[TRACE] Setting target computer to '\\MAN07536'
[TRACE] Adding job 'VNC_Mess.job'
[TRACE] Activating job 'VNC_Mess.job'
0
The operation completed successfully.

...and the job is not there.

Here is the code...
code:
$taskname='VNC_Mess.job'
$computer=$COMPUTER
$date='TODAY'
$time='$RUNTIME'
$type='ONCE'
$userid='taskadmin'
$userpw='password'
$comment='This task is to Show VNC Dissconnect Message.'
$command='%WINDIR%\mess.exe' ;crypted kix script
$parameters=''
scheduletask($taskname,$computer,$date,$time,$type,$userid,
$userpw,$comment,$command,$parameters)
? @SERROR
:END
GET $_
QUIT
;==========================================================
;==========================================================
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='%WINDIR%\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="%WINDIR%"'
$shellcmd = $shellcmd+ ' Comment="'+$comment+'"'
$shellcmd = $shellcmd+ ' Creator="'+@USERID+'"'
$shellcmd = $shellcmd+ ' Priority=Normal'
$shellcmd = $shellcmd+ ' Interactive=1'
$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+ ' /SM \\'+$computer
$shellcmd = $shellcmd+ ' /SAJ '+$taskname
$shellcmd = $shellcmd+ ' /SAC '+$taskname
SHELL "%COMSPEC% /e:1024 /c "+$shellcmd+" "
$scheduletask=@ERROR
ENDFUNCTION

If I don't use the 'Interactive' option the job gets pushed like it should, but problem is the 'MessageBox' doesn't display to the logged on user. It is running in the process window under the taskadmin account.

I guess the real question would be what do I need to do to get the logged on user to see that message box?

Here is the simple code for the mess.exe...
code:
BREAK ON 
$RC=MessageBox('The HelpDesk Technician has disconnected from your PC.'+@CRLF+
'Do you want to view the log file "C:\WinVNC_log.txt" ?',
@WKSTA,68)
IF(@ERROR='6') RUN 'NotePad.exe "C:\WinVNC_log.txt"' ENDIF
;[ 6 = YES ] [ 7 = NO ]
QUIT

TIA,
Rocco


Sealeopard
(KiX Master)
2003-03-07 03:42 PM
Re: scheduletask() error with 'Interactive'...

Why not just start a new process through WMI? That process would run under the account of the currenly logged-in user and the user will be able to interact with it. Alternatively, use the SENDMESSAGE() function to send a message to the user.

The 'startign remote procees' has been discussed numerous times already, please use the KiXtart BBS Search to retrieve the relevant threads.


Rocco Capra
(Hey THIS is FUN)
2003-03-07 03:55 PM
Re: scheduletask() error with 'Interactive'...

I've already done a search, but nothing answered my question. [Frown] So I had to ask.

SendMessage is easy, that works great, but I need to make it as simple as can be for the user. If I tell them where to find the log they never will. [Roll Eyes] If I give them a button to click to open the log, they will.

I don't know how to use the WMI stuff to well, can you give me a place to start? [Confused]

Also, as a side note at this point, have you ever used the 'Interactive' option sucessfully?

Thanks,
Rocco


Sealeopard
(KiX Master)
2003-03-07 04:08 PM
Re: scheduletask() error with 'Interactive'...

I don't want my users to 'interact' with my scripts [Wink] also, AFAIK, the 'interactive' is with regards to the user accoun the task run under.

See WMIKill() - stops a process amd modify to start a porcess.


Richard H.Administrator
(KiX Supporter)
2003-03-07 05:07 PM
Re: scheduletask() error with 'Interactive'...

Interactive (in the old scheduler at least) meant that it would "appear" on the console if a user logged in.

This is vital for things like ntbackup, as if this gets stuck for any reason - no tape in drive for example - it will just hang with a prompt. The next night it will fail to start because there is already a hung process running.

If you don't use the interactive switch it remains stuck in the background with no clue about what is going on.


Rocco Capra
(Hey THIS is FUN)
2003-03-07 05:41 PM
Re: scheduletask() error with 'Interactive'...

Ok Jens,

Ive looked at those UDF's as well as MSDN (dowloaded the wmi tutorial) and am more lost than ever! [Embarrassed]

What do I do with this to get it to work?...
code:
$COMPUTER='MAN07536'
$objWMIService=GetObject('winmgmts:{impersonationLevel=impersonate}!//'+$COMPUTER)
$RC=$objWMIService.Create("notepad.exe", null, null, intProcessID) ;+'\root\cimv2:Win32_Process'

[Frown]

Rocco


Sealeopard
(KiX Master)
2003-03-07 05:45 PM
Re: scheduletask() error with 'Interactive'...

Nearly there:
code:
$COMPUTER=@WKSTA

$objWMIService=GetObject('winmgmts:{impersonationLevel=impersonate}!//'+$COMPUTER+'\root\cimv2:Win32_Process')
? ''+@ERROR+' - '+@SERROR

$RC=$objWMIService.Create('notepad.exe')
? ''+@ERROR+' - '+@SERROR



Rocco Capra
(Hey THIS is FUN)
2003-03-07 05:57 PM
Re: scheduletask() error with 'Interactive'...

Thank you,
thank you very much.


Rocco Capra
(Hey THIS is FUN)
2003-03-07 06:04 PM
Re: scheduletask() error with 'Interactive'...

UUUhhhhhhgggggg.

It works for $COMPUTER=@WKSTA but not for remote PC. [Frown]

The remote PC is WIN2000 The kill proccess works but not starting.

I get "0's" for return codes but nothing happens on the remote PC at all.

code:
$COMPUTER'MAN07536'
?"$COMPUTER"
$objWMIService=GetObject('winmgmts:{impersonationLevel=impersonate}!//'+$COMPUTER+'\root\cimv2:Win32_Process')
? ''+@ERROR+' - '+@SERROR

$RC=$objWMIService.Create('%WINDIR%\mess.exe')
? ''+@ERROR+' - '+@SERROR



[ 07. March 2003, 18:06: Message edited by: Rocco Capra ]


LonkeroAdministrator
(KiX Master Guru)
2003-03-07 06:09 PM
Re: scheduletask() error with 'Interactive'...

well, at least windir should be different...
$RC=$objWMIService.Create('%%WINDIR%%\mess.exe')

should do little difference.


Sealeopard
(KiX Master)
2003-03-07 06:13 PM
Re: scheduletask() error with 'Interactive'...

Search the BBS for 'Win32_Process'. you'll find threads like this:

remote execution .

Also, there seems to be a change in the security model for Windows XP with regards to remote execution of scripts and having the user interact with this. However, don't have a source URL for this.


Les
(KiX Master)
2003-03-07 06:13 PM
Re: scheduletask() error with 'Interactive'...

Which %windir% would expand? Would it be the windir of the local or remote?

LonkeroAdministrator
(KiX Master Guru)
2003-03-07 06:15 PM
Re: scheduletask() error with 'Interactive'...

good question les [Razz]

Rocco Capra
(Hey THIS is FUN)
2003-03-07 06:34 PM
Re: scheduletask() error with 'Interactive'...

Well,

this works...
code:
$COMPUTER='MAN07536'
?"$COMPUTER"
$objWMIService=GetObject('winmgmts:{impersonationLevel=impersonate}!//'
+$COMPUTER+'\root\cimv2:Win32_Process')
? ''+@ERROR+' - '+@SERROR

$RC=$objWMIService.Create('mess.exe')
? ''+@ERROR+' - '+@SERROR
?'end'
GET $_

But is still not visable to the user.


LonkeroAdministrator
(KiX Master Guru)
2003-03-07 06:44 PM
Re: scheduletask() error with 'Interactive'...

sure [Big Grin]
from msdn:
quote:
The Create WMI class method creates a new process. A fully-qualified path needs to be specified in cases where the program to be launched is not in the search path of Winmgmt.exe. If the newly created process attempts to interact with objects on the target system without appropriate access privileges, it is terminated without notification to this method.

For security reasons the Win32_Process.Create method cannot be used to start an interactive process.



[ 07. March 2003, 19:32: Message edited by: Lonkero ]


Rocco Capra
(Hey THIS is FUN)
2003-03-07 07:06 PM
Re: scheduletask() error with 'Interactive'...

"For security reasons the Win32_Process.Create method cannot be used to start an interactive process."

Damn!!

[Mad]


Glenn BarnasAdministrator
(KiX Supporter)
2003-03-07 09:09 PM
Re: scheduletask() error with 'Interactive'...

FYI - in the work I've done with JT.Exe, the INTERACTIVE and HaltOnError boolean values do not seem to be implemented within JT. JT error-exits when those parameters are supplied. I can't even get it to TRY and use those params.

Glenn


Breaker
(Hey THIS is FUN)
2003-08-15 01:27 PM
Re: scheduletask() error with 'Interactive'...

Sorry to flog this old horse again - I take it that since this point no-one else has had any luck using the Interactive property within JT.exe?

Just checkin'...

[ 15. August 2003, 13:27: Message edited by: Breaker ]


LonkeroAdministrator
(KiX Master Guru)
2003-08-15 01:36 PM
Re: scheduletask() error with 'Interactive'...

one could always use the RPC bug to run code without admin privs! [Big Grin]

Sealeopard
(KiX Master)
2003-08-15 02:55 PM
Re: scheduletask() error with 'Interactive'...

Breaker:

The 'Interactive' and 'HaltOnError' options simple do not work. I've also never encountered a situation where I would need an interactive sessions. The beauty of the Task Scheduler, in my mind, is that it completely hides the scripts that I run under administrative accounts.