#179001 - 2007-08-09 01:35 PM
deny logon acroding to day and time
|
gf
Fresh Scripter
Registered: 2001-07-08
Posts: 29
|
Hi i would like to know if there is a way in kix to deny a group of users to logon monday - thursday from 1pm - 3pm
i am using the following to deny users to logon specifik workstations
IF LEFT(@WKSTA,3) = "LPC" IF LEFT(@USERID,1) = "e" $logof = logoff(1) ENDIF ENDIF
I have tried different methods with this as a "base"
IF INGROUP ("Elever") > 0
"check if it is mon,tue,we,thur AND tehe time is
$logof = logoff(1) ENDIF
Any sugestions ?
Regards Glenn
|
|
Top
|
|
|
|
#179006 - 2007-08-09 02:35 PM
Re: deny logon acroding to day and time
[Re: gf]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
Use a login script with the following example code. You'll need to adjust the tests as appropriate for your needs.
The basic idea is to set $Allow to true, then find ways to set it to false, such as workstation name, user name, group membership, or time of day.
Then, maybe, find a couple of ways to bend the rules, like Fri-Sun is fair game.
You can create more complex tests by creating values for each test, like $Day_OK, $Time_OK, $User_OK, and $Wksta_OK. Then set the $Allow value based on tests with these values in AND / OR combinations.
The TimeDiff() UDF can be used creatively to check a range of time, as illustrated here. TimeDiff is not sensitive to local time or display format.
Break Off ; exit if BREAK is pressed
$Allow = 1 ; allow by default
; Change allow status based on time of day - never allow between 13:00-15:00
; TimeDiff returns the number of minutes between the current time and 15:00 of the current day
; This value will be between 120 (at 13:00) and 0 (at 15:00) during tht time range not allowed.
; Before 13:00, it will be greater than 120, and after 15:00 it will be negative, thus the following test
; You need to download and include the TimeDiff() UDF in your script
$TVal = TimeDiff('now', @DATE + ' 15:00:00', 'M')
If $TVal < 120 And $TVal > 0
$Allow = 0
EndIf
; Change allow status base on workstation
$Allow = IIf(Left(@WKSTA, 3) = 'LPC', 0, $Allow)
; Change allow status base on group
$Allow = IIf(InGroup('Elever', 0, $Allow)
; continue with other allow tests as appropriate, setting $Allow to 0 if not permitted
; Process exceptions to the rules
; Override the allow value if the day is not in the range
; All users are allowed at any time on Fri-Sun
If Not InStr('MONTUEWEDTHU', Left(@DAY, 3)
$Allow = 1
EndIF
; If $Allow is zero at this point, the user should not be permitted,
; so perform a logoff
If Not $Allow
Logoff(1) ; exit the script - brea
EndIf
The TimeDiff UDF is here.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#179008 - 2007-08-09 02:45 PM
Re: deny logon acroding to day and time
[Re: Glenn Barnas]
|
gf
Fresh Scripter
Registered: 2001-07-08
Posts: 29
|
Hi Again
-> Gargoyle the reason for not using logon hours are, that 1-3 is just an example. I work at a bording school whrere i dont want pupils to logon from 17:00:00 to 18:15:00 and you cant do that with logon hours.
Mart i cant get your script to work.
Will $rc = LogOff(1) work on thin clients ( Terminal server?)
Regards Glenn
|
|
Top
|
|
|
|
#179010 - 2007-08-09 03:09 PM
Re: deny logon acroding to day and time
[Re: Mart]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
|
|
Top
|
|
|
|
#179011 - 2007-08-09 03:14 PM
Re: deny logon acroding to day and time
[Re: Mart]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
Glenn's example might be a better solution.
He means me (Glenn) not you (Glenn). 
I've had mixed results with the logoff() function. You might want to look into external solutions. I seem to recall that running explorer.exe?? with certain args would reliably log the user off.
You should probably experiment with different techniques for determining what's allowed and what's not, as I illustrated. My example used hard-coded values, but if I were doing this for real, I'd use an INI file and ReadProfileString() functions to load the parameters, so they could easily be changed. You could then do stuff like "if user is in group XXX, load time range XXX, replacing the default time range values with the extended/reduced time range allocated to this group's members"
If you use the TimeDiff() UDF, all you need to store is the end time, and the number of minutes before the end time that are permitted. You could reverse the logic and check the start time and number of minutes permitted..
$Start = '13:00' ; start of prohibited time period
$Limit = 120 ; # of Minutes prohibited from start time
; the above values should be read from a config file using ReadProfileString() - EG
; $Start = ReadProfileString('\\domain\netlogon\restrict.ini', 'DEFAULT', 'RestrictStartTime')
; $Limit = ReadProfileString('\\domain\netlogon\restrict.ini', 'DEFAULT', 'RestrictDuration')
$TVal = TimeDiff(@DATE + ' ' + $Start, 'now', 'M')
If $TVal >= 0 And $TVal <= $Limit
; log off!
EndIf
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#179019 - 2007-08-09 05:08 PM
Re: deny logon acroding to day and time
[Re: Mart]
|
gf
Fresh Scripter
Registered: 2001-07-08
Posts: 29
|
Hi thanks for all your input i am allmost done with the script. Just one last question: How would i go about executing the: rundll32 user32.dll,ExitWindowsEx from kix.
Igain, thank you very much.
Regards Glenn
|
|
Top
|
|
|
|
#179035 - 2007-08-09 10:01 PM
Re: deny logon acroding to day and time
[Re: Mart]
|
gf
Fresh Scripter
Registered: 2001-07-08
Posts: 29
|
I think he is taking the piss on me 
The rundll doesn't work on a terminal server but i solved it with the following lines in a bat file:
query session >session.txt for /f "skip=1 tokens=3," %%i in (session.txt) DO logoff %%i del session.txt
However i am still strugling I cant get any oytput from:
? $time Join(Split(@TIME, ":"), "")
Regards Glenn
|
|
Top
|
|
|
|
#179048 - 2007-08-09 10:54 PM
Re: deny logon acroding to day and time
[Re: gf]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
Why output to a text if you can query text in memory
for /F "usebackq skip=1 tokens=2" %i in (`query session`) DO echo %i
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1045 anonymous users online.
|
|
|