Page 1 of 1 1
Topic Options
#130329 - 2004-11-30 07:09 AM Trying to Schedule a One-Time Task
Skatterbrainz Offline
Starting to like KiXtart

Registered: 2002-10-17
Posts: 172
Loc: Virginia, USA
I want to fire off a one-time scheduled task at login for a particular user that forces them to logoff in 30 minutes from their login. I've been trying various approaches with the SCHTASKS command but am not having any luck getting it to work from Kix. The Kix script is below, with the BAT file code below that. The BAT file works fine by itself.

Code:

Break ON
$=MessageBox("Configuring Automatic Logoff...","Network Security",64,2)
Shell "%COMSPEC% /C schtasks /delete /tn AutoLogoff /f"
Shell "%COMSPEC% /C schtasks /create /sc minute /mo 30 /u System /tn AutoLogoff /tr \\utopia\netlogon\autologoff.bat"
Return


BAT file AUTOLOGOFF.BAT
Code:

@echo off
title Forced Automatic Logoff
echo You are now required to logoff in 30 seconds...
echo *** bye bye ....
shutdown -l -f -t 30


Does anyone know of a better way to do this? Am I leaving something out?
_________________________
silence is golden, but duct tape is silver

Top
#130330 - 2004-11-30 09:33 AM Re: Trying to Schedule a One-Time Task
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
So what happens? What have you tried?

You'll need to tell us up front, or we will be going around in circles trying to get the information out of you.

A couple of obvious ones to begin with:
  • Do the SCHTASKS work if you type them in manually at the command line?
  • Once you've run the script have you checked to see if anything has been scheduled?
  • Why are you not checking (and displaying) @ERROR and @SERROR after the Shell commands? You will be missing any errors.

Top
#130331 - 2004-11-30 09:35 AM Re: Trying to Schedule a One-Time Task
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
By default the task can not access network resources so the task would fail.

There are UDFs for scheduling as well.

What clients do you need to support? NT/2000/XP/2003?

What version of KiXtart are you using?

Do your users have Admin rights on their own local systems?


TaskScheduleControl() - Library of UDFs to manage Windows Task Scheduler
http://www.kixhelp.com/udfs/udf/83077.htm

Scheduled Task Control Library for JT.EXE
http://www.kixhelp.com/udfs/udf/111470.htm

SCHEDULETASK() - Schedules a task on any computer using the Task Scheduler
http://www.kixhelp.com/udfs/udf/81888.htm

XP/2003 have a built-in SHUTDOWN command
Quote:

Usage: shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c "comment"] [-d up:xx:y
y]

No args Display this message (same as -?)
-i Display GUI interface, must be the first option
-l Log off (cannot be used with -m option)
-s Shutdown the computer
-r Shutdown and restart the computer
-a Abort a system shutdown
-m \\computername Remote computer to shutdown/restart/abort
-t xx Set timeout for shutdown to xx seconds
-c "comment" Shutdown comment (maximum of 127 characters)
-f Forces running applications to close without warning
-d [u][p]:xx:yy The reason code for the shutdown
u is the user code
p is a planned shutdown code
xx is the major reason code (positive integer less than 256)
yy is the minor reason code (positive integer less than 65536)





How To Troubleshoot Scheduled Tasks in Windows XP
http://support.microsoft.com/?id=308558

How To Use the Remote Shutdown Tool to Shut Down and Restart a Computer in Windows 2000
http://support.microsoft.com/?id=317371

Top
#130332 - 2004-12-01 06:04 AM Re: Trying to Schedule a One-Time Task
Skatterbrainz Offline
Starting to like KiXtart

Registered: 2002-10-17
Posts: 172
Loc: Virginia, USA
Sorry for leaving out the details (mentioned above by Richard): Both clients (2) are XP SP2, I'm using 2003 on the server with Kix 4.22. When I run the SCHTASKS command manually it works, even on the test user account (no users but myself have admin rights). The SHUTDOWN script (shown in the first post) works fine as well. The only problem is that the RUN or SHELL lines in my Kix file don't seem to create a scheduled task.

Ideally, I would like to be able to launch something that runs in the background at each logon, that would monitor the current day/time and compare against the User logon hours (applied to their user account in AD). If the day/time falls outside of that, log them off. The GPO setting "Force Logoff when Logon hours expire" apparently does not do this and is only intended to block access to resources (go figure, stupid policy title).
_________________________
silence is golden, but duct tape is silver

Top
#130333 - 2004-12-01 06:45 AM Re: Trying to Schedule a One-Time Task
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
The ForceLogOff works in that it forces the user off of the Server connection as it was intended.

Here is a link that discusses it more.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/566.mspx

As for the scheduled task not being created, as you have it shown it needs a password which you're not supplying. You can't use /U for the SYSTEM account, you need to use /RU

If that does not correct the issue please let me know, but this works for me, however I don't think you have the time set correctly either as it wants to pretty much run as soon as it is created.

Code:
Break On

Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')

Dim $MB
$MB=MessageBox("Configuring Automatic Logoff...","Network Security",64,2)
Shell '%COMSPEC% /C schtasks /delete /tn AutoLogoff /f >nul 2>nul'
Shell '%COMSPEC% /C schtasks /create /sc minute /mo 30 /ru System /tn AutoLogoff /tr \\utopia\netlogon\autologoff.bat >nul 2>nul'





Top
#130334 - 2004-12-01 09:37 AM Re: Trying to Schedule a One-Time Task
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
You missed the third item in the list.

Errors with things like SHELL and RUN will be slient in many scenarios. The only way that you will be able to tell that there was an error is to check and display @ERROR and @SERROR.

Specifically there is a fairly well known problem where %COMSPEC% contains spaces or other characters which cause problems.

You are also ditching any error output from the command using "2>nul", so if there is a problem with the application you won't see the error either.

Get it working first, then silence it.

see how this works for you:
Code:
Break On
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('WrapAtEOL','On')

Dim $MB,$sSilence

; ** Uncomment the following line to silence the script once it is working **
; $sSilence=' >nul 2>nul'

$MB=MessageBox("Configuring Automatic Logoff...","Network Security",64,2)

If Not $sSilence "Removing old task..."+@CRLF EndIf
Shell '"'+%COMSPEC%+'" /C schtasks /delete /tn AutoLogoff /f '+$sSilence
; Note, ignoring errors for this command

If Not $sSilence "Creating new logoff task..."+@CRLF EndIf
Shell '"'+%COMSPEC%+'" /C schtasks /create /sc minute /mo 30 /ru System /tn AutoLogoff /tr \\utopia\netlogon\autologoff.bat '+$sSilence
If @ERROR
$MB=MessageBox("Could not create auto logoff task, Reason"+@CRLF+"["+@ERROR+"] "+@SERROR,"Task creation failure")
EndIf



The changes wrap the expanded %COMSPEC% value in quotes to avoid problems with spaces, and pop up a message if the add task command fails.

Once you have got the code working to your satisfaction, uncomment the $sSilence=... line to quiten thing down a bit.

Top
#130335 - 2004-12-02 12:01 AM Re: Trying to Schedule a One-Time Task
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Good code and information Richard.

I'm the one who silenced it not Davis. Question, which item specifically did you mean? The code did work for me but did not set the time correctly either from DOS typing it in or from KiXtart but I did not spend any time to check on why so I silenced it, but yes I agree... get it working first, then silence it.

On another note which I did mention previously. Using the SYSTEM account for this task will fail anyways as the SYSTEM account has no rights to access the batch file on the remote server.

Top
#130336 - 2004-12-02 01:49 AM Re: Trying to Schedule a One-Time Task
Anonymous
Unregistered


Thanks (everyone)! I will give this a try. I really appreciate the help.
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 883 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.059 seconds in which 0.027 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