Sign in to follow this  
Followers 0
jazzyjeff

Preventing concurrent logins script

3 posts in this topic

hello,

So I wanted to create a script that would allow for a user to only be logged in once at any time. I work for a school and there has been a need to stop students from providing their login credentials to friends who have their accounts disabled.

I wanted to create a script based on the "Limit Logins" application. A script executes when the user logs in and checks for a record of the user in the spreadsheet (CSV file). If the users login details are already in the spreadsheet, then they will receive a message on the screen telling them that they will be logged off in 10 seconds and the machine then logs them off. If their username isn't in the spreadsheet, it adds a log of their username to the list.

I then have a log off script that will remove the logged in user from the list when they log off. That way when they log in again, their name is not in the spreadsheet and when they log in again they won't receive a concurrent login message.

The log on script seems to be working fine (if you see any errors though, or ways to improve it please let me know).

The log off script is the problem. I am unable to get the script to find the user and then remove that user from the list. The script I have deletes everything in the spreadsheet.

Does anyone know of how I can just delete a specific user?

Here is the code I have for the log off script. I will post the logon script below that too, in case it helps.

#include <_RemoveLineInFile.au3>
#include <excel.au3>
#include <array.au3>
#include <file.au3>

Global $i_opt, $i_CaseSensitive

$h_path = "\\app2\logs$\Student Logins.csv"
$s_search = @UserName

_RemoveLineInFile($h_path,$s_search,$i_opt = 1,$i_CaseSensitive = 0)

This my login script.

#include <excel.au3>
#include <array.au3>

$TITLE = ("Username, Computer Name, IP Address, Time, Date")
$Login = (@UserName & "," & @ComputerName & "," & @IPAddress1 & "," & @HOUR & ":" & @MIN & ":" & @SEC & "," & @MON & "/" & @MDAY & "/" & @YEAR)
$exStudent = "\\app2\logs$\Student Logins.csv"

$oExcel = _ExcelBookOpen($exStudent,0)
$exArray1 = _ExcelReadArray ($oExcel,1,2,2000,1)
_ExcelBookClose($oExcel)

For $y=1 to UBound($exArray1) -1
    If $exArray1[($y)] = @UserName Then
        MsgBox(48,"Yikes!","You are already logged in elsewhere. You will be logged off in 10 seconds.",10)
        Run("cmd /c shutdown /l /f")
    Else
        FileWriteLine("\\app2\logs$\Student Logins.csv", $Login)
    EndIf
ExitLoop
Next

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Why not just create a text file on a server share EG. \\server\logononceshare$\@username.txt and write the computername (@computername) inside the file (or some other attribute like MAC address).

Do an if statement-

IF FILEEXISTS("\\server\logononceshare$\" & @username. & "txt") THEN
;Open the file, 
   $fLogonFile = FileOpen(("\\server\logononceshare$\" & @username. & "txt",0)
   
;check if the computer name matches and if it does not match, 
   $Line = Filereadline($fLogonfile, 1)
     If $line <> @computername Then
        Run("cmd /c shutdown /l /f")
     Endif
;some other house keeping stuff if you want to map drives, etc
;Create the file on the share as the last step
$fCreatePass = Fileopen("\\server\logononceshare$\" & @username. & "txt", 1) 
Filewriteline($fCreatepass, @computername)

If it does match let them log on (just in case the file got left behind due to a power outage, BSOD, etc)

Then on your log off script, check if the file exists and check the computer name logged in the file,

If both are true, delete the file.

You can then use your CSV to track logons so you know when there are duplicate logons happening.

If you want to get fancy, use INI files and "Encrypt" the data in the keys you create.

Edited by Legacy99

Share this post


Link to post
Share on other sites

I thought about the creating a text file for each user, but I thought it'd be nicer to have the logs generated in one spreadsheet. I'll try the text file idea though. I think I'd be able to get it working like that.

As I get more experience with the AutoIT, I'll try and figure it out.

I'll let you know how it goes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0