ChrisH Posted July 29, 2005 Posted July 29, 2005 (edited) Ok I have written the VBS versions of the scripts by Murat Yildirimoglu as posted by Russdev in this post. Use at your own risk I have only tested them at home. You need to set the server and share at the top. The users must have change permission on the share. If you just want to test without getting logged off then Change this line: WshShell.Run "logoff" To 'WshShell.Run "logoff" and uncomment these lines 'Wscript.Echo "The user is already logged on" Else 'Wscript.Echo "The user is not logged on" So they read Wscript.Echo "The user is already logged on" Else Wscript.Echo "The user is not logged on" I can think of a few improvements I can make to this and will do them at a later date Full listing here and a rar file with both in '************************************************************************* '* * '* Limit login script (Login Part) * '* Version 0.1 by 29/07/2005 * '* This is a VBS version of a script written by Murat Yildirimoglu * '* USE THIS SCRIPT AT YOUR OWN RISK * '* I TAKE NO RESPONSIBILTY FOR ANYTHING COULD HAPPEN AS A RESULT * '* OF RUNNING THIS SCRIPT * '* * '************************************************************************* 'Begin Constant Declaration Const Server_Name = "megacity1" 'The server the shared directory will sit on Const Share_Name = "logon$" ' The share name Const ForReading = 1 Const ForAppending = 8 ' Begin Variable declaration Set WshShell = WScript.CreateObject("WScript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set ObjFSO = CreateObject("Scripting.FileSystemObject") Dim StrUserName ' Current user Dim StrStrMachineName Dim StrStrPathName Dim StrStrMachineFile Dim StrStrUserFile '************************* Main Code ************************* 'On Error Resume Next StrUserName = "" ' Wait until the user is really logged in... While StrUserName = "" WScript.Sleep 100 ' 1/10 th of a second StrUserName = WSHNetwork.UserName ' Get the user name Wend StrMachineName = WshNetwork.ComputerName 'Get the machine Name StrPathName = "\\" & Server_Name & "\" & Share_Name & "\" If ObjFSO.FileExists (StrPathName & StrUserName & ".txt") Then WshShell.Run "logoff" 'Wscript.Echo "The user is already logged on" Else 'Wscript.Echo "The user is not logged on" Set StrUserFile = ObjFSO.CreateTextFile(StrPathName & StrUserName & ".txt") StrUserFile.WriteLine StrUserName & " " & "has logged onto" & " " & StrMachineName StrUserFile.Close Set StrMachineFile = ObjFSO.CreateTextFile(StrPathName & StrMachineName & ".txt") StrMachineFile.WriteLine StrUserName & " " & "has logged onto" & " " & StrMachineName StrMachineFile.Close End If '************************************************************************* '* * '* Limit login script (Logoff Part) * '* Version 0.1 29/07/2005 * '* This is a VBS version of a script written by Murat Yildirimoglu * '* USE THIS SCRIPT AT YOUR OWN RISK * '* I TAKE NO RESPONSIBILTY FOR ANYTHING COULD HAPPEN AS A RESULT * '* OF RUNNING THIS SCRIPT * '* * '************************************************************************* 'Begin Constant Declaration Const Server_Name = "megacity1" 'The server the shared directory will sit on Const Share_Name = "logon$" ' The share name ' Begin Variable declaration Set WshShell = WScript.CreateObject("WScript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set ObjFSO = CreateObject("Scripting.FileSystemObject") Dim StrUserName ' Current user Dim StrMachineFile Dim StrPathName '************************* Main Code ************************* On Error Resume Next StrUserName = WSHNetwork.UserName ' Get the user name StrMachineName = WshNetwork.ComputerName 'Get the machine Name StrPathName = "\\" & Server_Name & "\" & Share_Name & "\" If ObjFSO.FileExists (StrPathName & StrUserName & ".txt") Then 'Delete the files if they exist ObjFSO.DeleteFile (StrPathName & StrUserName & ".txt") ObjFSO.DeleteFile (StrPathName & StrMachineName & ".txt") End If logonlimit.rar Edited March 12, 2014 by ChrisH
russdev Posted July 29, 2005 Posted July 29, 2005 great... will try when get back in to work in a week... if you ran msgbox and than ran the logoff does the script hold at msgbox until clicked ok.. As thinking it would be best if it telss the user why it is logging off... Rus
Ric_ Posted July 29, 2005 Posted July 29, 2005 if you ran msgbox and than ran the logoff does the script hold at msgbox until clicked ok.. As thinking it would be best if it telss the user why it is logging off... Rus It's always more fun to do it without telling them Just a thought but if the text file that it writes contains the computer name of the logged on user, you could log that user off instead and allow the new user to log on - use something like pslogoff for this. If you are feeling generous, you could even tell the user why they are suddenly being forced to logoff and give them 30secs to save their work.
russdev Posted July 29, 2005 Posted July 29, 2005 that's a good idea.. But on that score would need to make sure script logged everything so can check back over logs to see why a user was logged off.. russ
Ric_ Posted July 29, 2005 Posted July 29, 2005 @Russ: That goes without saying. Something along the lines of " tried to log onto whilst logged onto - like that's going to happen! Fool!"?
ChrisH Posted July 29, 2005 Author Posted July 29, 2005 Some of these things I have already thought about doing as an update. For this version though I just wanted to copy the batch version as close as possible then add from there. If we get a good list together I'm sure between us we can get it how we want it. I'm just getting my head round database access from VBS at the mo. I have had to read the same 4 pages 3 times so far
ChrisH Posted July 29, 2005 Author Posted July 29, 2005 Looking at this all now I think this can be all done into a database. I'm thinking a MYSQL database that can hold 2 tables. One with the history of logons and one that holds current logons. Also then query the history through ASP, which is something somebody else has already implemented and posted about. Any thoughts? Course I want to do a HTA for my user import script first
ChrisH Posted October 14, 2005 Author Posted October 14, 2005 Anyone currently using this and would like to provide any feedback? I am still working of the database version as every time I start coding it I seem to get dragged of to do something else :?
russdev Posted October 14, 2005 Posted October 14, 2005 start testing it but had problesm but not down to script but down to getting rm to run accept scripts and not error out goiong to look at it next week if get time. russ
peterduckmanton Posted March 8, 2006 Posted March 8, 2006 I have been working on a version of the script that logs access, prompts the user to ask which machine they wish to log out from, and also works with RM CC3. I have been using it for the past month or so, and it is working well.logoff.vbslogin.vbs
ChrisH Posted March 8, 2006 Author Posted March 8, 2006 Just had a quick scan and that looks very good One day im going to have to sit down and start finishing of all the half done projects I have started I dont seem to get the time anymore to sit down for any period of time and bash out code :?
Snuffkins Posted March 8, 2006 Posted March 8, 2006 Just started having a little test of it and it works a treat... Wonder if there's anyway of forcing them to click yes or no and not be able to do anything else till they have??? Cause with the kids here i know they'll just ignore it and work around it .
plexer Posted March 8, 2006 Posted March 8, 2006 Looks very good I developed a vbs to do this a while ago and never thought about sticking it up as I haven't actively used it for a while. My version would sometimes not clear up after a user logged off so then it wouldn't let them logon from anywhere Ben
ChrisH Posted March 8, 2006 Author Posted March 8, 2006 The only thing that does concern me though is the username and password in the script. Im sure something else could be done to make that a little more secure though.
peterduckmanton Posted March 8, 2006 Posted March 8, 2006 Just started having a little test of it and it works a treat... Wonder if there's anyway of forcing them to click yes or no and not be able to do anything else till they have??? Cause with the kids here i know they'll just ignore it and work around it . The MsgBox "4372" forces focus, and thus means the box cannot be avoided. The version I have written clears up after itself if people aren't logging out correctly. I did think about putting the passwords into a separate file or by writting them in hex, if anyone has any ideas of best way of storing these details then let me know.
Snuffkins Posted March 8, 2006 Posted March 8, 2006 That's not what i meant. Because i have a lot of kids here as i'm sure most schools have borrowing *cough* *cough* other people user accounts they will just drag the msgbox to one side and carry on working. Either that or it's not working right for me i've probably done something wrong...
steve Posted October 28, 2006 Posted October 28, 2006 I've been butchering these scripts this morning to try and get a popup telling the user they will be logged off - no choice if already logged on. part of logon.vbs trying to change: If StrUserName = strUser Then 'The user logged on to the other computer is the same as the user trying to logon to this computer 'Open messagebox informing user that they are already logged on strResponse = msgbox("You are already logged in at computer " & strMachine & "! You will now be logged off this computer.",4144,"Duplicate Login") if strResponse = 1 then 'The answer is OK 'Write to the log file Set filetxt = objFSO.OpenTextFile(strpathname & "logs\" & formatdatetime(Now(),vblongdate) & ".log", 8, True) filetxt.writeline(Now() & ", " & StrUserName & ", " & StrMachineName & ", User logged in elsewhere, decided not to login here") filetxt.close WshShell.Run "logoff" What I'd like to do is have a time out on the message, so even if its not clicked it, it will still log off after say 60 seconds. From what I've read on the t'internet, the msgbox needs changing to a objshell.popup which would allow a timeout to be specified. I tried using the following: Set objShell = CreateObject("Wscript.Shell") ' added with other set parts at top of script. strResponse = objshell.popup("You are already logged in at computer " & strMachine & "! You will now be logged off this computer.",60,"Duplicate Login",4144) Only trouble is my vbs is pretty limited. Can anyone help?
plexer Posted October 28, 2006 Posted October 28, 2006 How about something like: Set objShell = CreateObject("Wscript.Shell") intReturn = objShell.Popup("You are already logged in at computer " & strMachine & "! You will now be logged off this computer.", 10, "Duplicate Login", Ok_Button) If intReturn = 1 Then Wscript.Echo "You clicked the ok button. This would log you off" Else Wscript.Echo "The popup timed out. This would log you off after a timeout" End If ??? You don't seem to be able to make a pop up modal though. Ben
steve Posted November 24, 2006 Posted November 24, 2006 Just got round to this and it works a treat. If you're down at BETT give me a shout, I'll get you a pint. :drinkers: :twisted: The kids don't know whats hit them
alonebfg Posted November 28, 2006 Posted November 28, 2006 i have just installed limit login from the microsoft web site it seems to work really well can also se a display time to say what machines logged into also logs it in the event log seems to work really well.
mac_shinobi Posted November 29, 2006 Posted November 29, 2006 will try some stuff out tommorow evening when I get back after work and see if I can come up with something As for now hows this for a solution with regards to the message box displaying for a certain time period : http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul06/hey0727.mspx
edie209 Posted February 13, 2007 Posted February 13, 2007 I have finally got a chance to have a look at limitlogon, Steve was kind enough to send me the script that he modified with oher peoples help. But I have run into a problem. on PC1 the first logon I get this error line 70 Char 4 Path not found Set filetxt = objFSO.OpenTextFile(strpathname & "logs\" & formatdatetime(Now(),vblongdate) & ".log", 8, True) and on PC2 logging on with the same user account, it recognises that the user account is already logged in and on which machine, I am then asked to click ok to be logged off, but then I get this error Line 91 Char 6 Path not found Set filetxt = objFSO.OpenTextFile(strpathname & "logs\" & formatdatetime(Now(),vblongdate) & ".log", 8, True) and the machine remains logged on. here is the full logon script 'Begin Constant Declaration Const Server_Name = "server" 'The server the shared directory will sit on Const Share_Name = "limitlogon$" ' The share name Const ForReading = 1 Const ForAppending = 8 Const TIMEOUT = 60 ' Begin Variable declaration Set WshShell = WScript.CreateObject("WScript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set ObjFSO = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("Wscript.Shell") Dim StrUserName ' Current user Dim StrStrMachineName Dim StrStrPathName Dim StrStrMachineFile Dim StrStrUserFile Dim strResponse Dim textstream Dim strMachine Dim strUser Dim filetxt '************************* Main Code ************************* 'On Error Resume Next StrUserName = "" strResponse = "" ' Wait until the user is really logged in... While StrUserName = "" WScript.Sleep 100 ' 1/10 th of a second StrUserName = WSHNetwork.UserName ' Get the user name Wend StrMachineName = WshNetwork.ComputerName 'Get the machine Name StrPathName = "\\" & Server_Name & "\" & Share_Name & "\" If ((StrUserName = "CyberCafe") OR (StrUserName = "ils")) Then 'Write to log file, do not check for multiple logins. Set filetxt = objFSO.OpenTextFile(strpathname & "logs\" & formatdatetime(Now(),vblongdate) & ".log", 8, True) filetxt.writeline(Now() & ", " & StrUserName & ", " & StrMachineName) filetxt.close Else If ObjFSO.FileExists (StrPathName & StrUserName & ".txt") Then 'If the file exists then the user is already logged in. Set StrUserFile = ObjFSO.CreateTextFile(StrPathName & StrUserName & "1.txt") StrUserFile.WriteLine StrMachineName StrUserFile.WriteLine StrUserName & " " & "has logged onto" & " " & StrMachineName & " at " & NOW() StrUserFile.Close 'Read the machine name from username file Set StrUserFile = ObjFSO.GetFile(StrPathName & StrUserName & ".txt") set textstream = StrUserFile.openastextstream(1,-2) strMachine = textstream.readline if strMachineName = strmachine then 'The user logged on to this computer, but didn't log out properly Set StrUserFile = ObjFSO.CreateTextFile(StrPathName & StrUserName & ".txt") StrUserFile.WriteLine StrMachineName StrUserFile.WriteLine StrUserName & " " & "has logged onto" & " " & StrMachineName & " at " & NOW() StrUserFile.Close Set StrMachineFile = ObjFSO.CreateTextFile(StrPathName & StrMachineName & ".txt") strMachineFile.WriteLine strUserName StrMachineFile.WriteLine StrUserName & " " & "has logged onto" & " " & StrMachineName & " at " & NOW() StrMachineFile.Close 'Write to the log file Set filetxt = objFSO.OpenTextFile(strpathname & "logs\" & formatdatetime(Now(),vblongdate) & ".log", 8, True) filetxt.writeline(Now() & ", " & StrUserName & ", " & StrMachineName & ", User didn't log out of this machine properly earlier") filetxt.close ObjFSO.DeleteFile (StrPathName & StrUserName & "1.txt") Else 'The user is logged on at another computer 'Read the username from the machine file If ObjFSO.FileExists (StrPathName & StrMachine & ".txt") Then Set StrUserFile = ObjFSO.GetFile(StrPathName & StrMachine & ".txt") set textstream = StrUserFile.openastextstream(1,-2) strUser = textstream.readline Else strUser = "" End If If StrUserName = strUser Then 'The user logged on to the other computer is the same as the user trying to logon to this computer 'Open messagebox informing user that they are already logged on intReturn = objShell.Popup("You are already logged in at computer " & strMachine & "! You will now be logged off this computer.", 30, "Duplicate Login", Ok_Button) If intReturn = 1 Then Wscript.Echo "You clicked the ok button. You will now be logged off" Set filetxt = objFSO.OpenTextFile(strpathname & "logs\" & formatdatetime(Now(),vblongdate) & ".log", 8, True) filetxt.writeline(Now() & ", " & StrUserName & ", " & StrMachineName & ", User logged in elsewhere, decided not to login here") filetxt.close WshShell.Run "\\server\limitlogon$\logoff.exe /n" Else Wscript.Echo "Logon timed out. You will now be logged off" Set filetxt = objFSO.OpenTextFile(strpathname & "logs\" & formatdatetime(Now(),vblongdate) & ".log", 8, True) filetxt.writeline(Now() & ", " & StrUserName & ", " & StrMachineName & ", User logged in elsewhere, decided not to login here") filetxt.close WshShell.Run "\\server\limitlogon$\logoff.exe /n" End If Else 'Another User has logged onto the other computer Set StrUserFile = ObjFSO.CreateTextFile(StrPathName & StrUserName & ".txt") StrUserFile.WriteLine StrMachineName StrUserFile.WriteLine StrUserName & " " & "has logged onto" & " " & StrMachineName & " at " & NOW() StrUserFile.Close Set StrMachineFile = ObjFSO.CreateTextFile(StrPathName & StrMachineName & ".txt") strMachineFile.WriteLine strUserName StrMachineFile.WriteLine StrUserName & " " & "has logged onto" & " " & StrMachineName & " at " & NOW() StrMachineFile.Close 'Write to the log file Set filetxt = objFSO.OpenTextFile(strpathname & "logs\" & formatdatetime(Now(),vblongdate) & ".log", 8, True) filetxt.writeline(Now() & ", " & StrUserName & ", " & StrMachineName & ", User didn't log out of other machine correctly") filetxt.close ObjFSO.DeleteFile (StrPathName & StrUserName & "1.txt") End If End if Else 'The user is not already logged in, so allow them to login without any questions. Set StrUserFile = ObjFSO.CreateTextFile(StrPathName & StrUserName & ".txt") StrUserFile.WriteLine StrMachineName StrUserFile.WriteLine StrUserName & " " & "has logged onto" & " " & StrMachineName & " at " & NOW() StrUserFile.Close Set StrMachineFile = ObjFSO.CreateTextFile(StrPathName & StrMachineName & ".txt") strMachineFile.WriteLine strUserName StrMachineFile.WriteLine StrUserName & " " & "has logged onto" & " " & StrMachineName & " at " & NOW() StrMachineFile.Close 'Write to the log file Set filetxt = objFSO.OpenTextFile(strpathname & "logs\" & formatdatetime(Now(),vblongdate) & ".log", 8, True) filetxt.writeline(Now() & ", " & StrUserName & ", " & StrMachineName & ", User logged in OK") filetxt.close End If End If
ChrisH Posted February 13, 2007 Author Posted February 13, 2007 Is your server actually called "server" ?
edie209 Posted February 13, 2007 Posted February 13, 2007 no my server is named invincible, I have changed that but I just edited it to make it easier on the forum.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now