Page 1 of 1 1
Topic Options
#163942 - 2006-07-03 02:43 PM Limit login to one machine at any given time
admad1 Offline
Fresh Scripter

Registered: 2006-07-03
Posts: 8
Hi Guys
Can anyone point me to an example script which limits login to more than one computer at a time. I used this on our old servers

REM h: /delete
REM logoff.exe resides in \windows (or winnt)\system32 folder
NET USE H: \\LRSFPS01\%USERNAME%
if exist H: goto end
if not exist H: goto logout
:logout
echo Y | logoff.exe
:end

Which worked fine from a batch file but we now use kiktart and I havent a clue how to integrate this into our current script. Is there a sample script that I might work with to try and get this working, our studenst are logging in all over the place and useing each others accounts when there's has been locked due to misuse.

Regards
Kili

Top
#163943 - 2006-07-03 03:04 PM Re: Limit login to one machine at any given time
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Code:
USE H: "\\LRSFPS01\"+%USERNAME%
If @ERROR=99 $=LogOff(1) EndIf



You will need to find out what error code is returned when the connection limit is reached and replace the "99".

You could check for *any* error, but then the user would be logged off if for example the share was unavailable for some reason.

Top
#163944 - 2006-07-03 04:18 PM Re: Limit login to one machine at any given time
admad1 Offline
Fresh Scripter

Registered: 2006-07-03
Posts: 8
Hi Richard. Thanks for taking the time to answer me. Would I place this in my batch file or in my kix script?
Top
#163945 - 2006-07-03 05:34 PM Re: Limit login to one machine at any given time
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
In your KiXtart script.

If you really don't care what reason the H: drive did not map you could do this:
Code:

USE H: /delete /persistent
USE H: "\\LRSFPS01\"+%USERNAME%
If @ERROR $=LogOff(1) EndIf


Top
#163946 - 2006-07-04 08:37 AM Re: Limit login to one machine at any given time
admad1 Offline
Fresh Scripter

Registered: 2006-07-03
Posts: 8
Thank you Richard.

This is the actual home path showing in ad account page

\\lrs.nameedu.local\DFS\Home Folders\Students\2003\%username%

The problem as I see it is that I have 5 paths a dont know how to tell kix to check all paths
\Students\2001\
\Students\2002\
\Students\2003\
\Students\2004\
\Students\2005\

USE H: /delete /persistent (This deletes the mapping I understand that bit)
USE H: "\\LRSFPS01\"+%USERNAME% (This maps h: to the username)
If @ERROR $=LogOff(1) EndIf
(It's this bit I dont understand if there's an error logoff (1) . How does this code check to see if the h: is already mapped and how do I integrate this to check all paths

Sorry for being so dumb I'm not very good at scripting just basic batch files hopefully I will pick this stuff up eventually.

admad1


Edited by admad1 (2006-07-04 09:06 AM)

Top
#163947 - 2006-07-04 09:34 AM Re: Limit login to one machine at any given time
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Code:
If @ERROR $=LogOff(1) EndIf



The "If @ERROR" check to see if there was *any* error when the attempt was made to map the drive. It doesn't need to check if the drive mapping is in place.

If there was any error then the user is logged off.

As I mentioned, it would be better to check for the actual error that occurs when you try to map to a drive which has a limit set, but I don't know what that error number might be.

You can find the number yourself. Try to map to a drive which is already at its limit and you should get a specific error number that you can then use in the conditional to avoid false positives.

Code:
USE H: /delete /persistent
USE H: @HOMESHR
If @ERROR
$=MessageBox("Cannot map home share, reason: ["+@ERROR+"] "+@SERROR, "Logon error",0+16+4096,30)
$=LogOff(1)
EndIf



The code above displays the reason for logging off in a pop-up message box. Once you know the value of @ERROR you could change the conditional to "If @ERROR=x" where "x" is the value displayed between the "[]" characters in the message.

I've also changed the mapping so that it uses @HOMESHR rather than a hard-coded path. @HOMESHR is the value from user manager or AD, so it's much more portable and gets around your problem of having the home shares in many different places.

Top
#163948 - 2006-07-04 10:26 AM Re: Limit login to one machine at any given time
admad1 Offline
Fresh Scripter

Registered: 2006-07-03
Posts: 8
Thanks Richard. I'll see if I can put this all toghther time to get my brain into gear.

Many Thanks

Top
#163949 - 2006-07-04 10:38 AM Re: Limit login to one machine at any given time
admad1 Offline
Fresh Scripter

Registered: 2006-07-03
Posts: 8
Hi Richard just a quick query. I need to apply this to students only within the script. This script is used by staff as well so I've got this

---------------
If InGroup("All Students")
USE H: /delete /persistent
USE H: @HOMESHR
If @ERROR
$=MessageBox("Cannot map home share, reason: ["+@ERROR+"] "+@SERROR, "Logon error",0+16+4096,30)
$=LogOff(1)
EndIf
--------------
Would this work with two if statments and only one endif or do I need to break this apart with another endif.

Regards
Amdad1

Top
#163950 - 2006-07-04 11:26 AM Re: Limit login to one machine at any given time
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
every if has to have its correspondig endif
_________________________



Top
#163951 - 2006-07-04 11:28 AM Re: Limit login to one machine at any given time
admad1 Offline
Fresh Scripter

Registered: 2006-07-03
Posts: 8
cheers
Top
#163952 - 2006-07-04 11:44 AM Re: Limit login to one machine at any given time
admad1 Offline
Fresh Scripter

Registered: 2006-07-03
Posts: 8
How would I constuct this with only one if and endif?

---------------
If InGroup("All Students")
USE H: /delete /persistent
USE H: @HOMESHR
endif >>>>>>>>>> is this correct and would it work this way
If @ERROR
$=MessageBox("Cannot map home share, reason: ["+@ERROR+"] "+@SERROR, "Logon error",0+16+4096,30)
$=LogOff(1)
EndIf
--------------

cheers
admad1

Top
#163953 - 2006-07-04 11:56 AM Re: Limit login to one machine at any given time
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Use CODE tags when posting, it will preserve formatting and make your code much more easy to read.

It will also five you a clue where the EndIF's should be:
Code:
If InGroup("All Students")
USE H: /delete /persistent
USE H: @HOMESHR
If @ERROR
$=MessageBox("Cannot map home share, reason: ["+@ERROR+"] "+@SERROR, "Logon error",0+16+4096,30)
$=LogOff(1)
EndIf
EndIf


Top
#163954 - 2006-07-04 11:59 AM Re: Limit login to one machine at any given time
admad1 Offline
Fresh Scripter

Registered: 2006-07-03
Posts: 8
Thanks Richard. Now that you shown it I can see where I went wrong. I did not realise you can have an if statment within an if statment. I'll give it a try and thanks for your patenice

admad

Top
Page 1 of 1 1


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

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

Generated in 0.17 seconds in which 0.114 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