+ Post New Thread
Page 2 of 2 FirstFirst 12
Results 16 to 30 of 30
Scripts Thread, Limit Logon VBS Version in Coding and Web Development; Originally Posted by Snuffkins Just started having a little test of it and it works a treat... Wonder if there's ...
  1. #16

    Join Date
    Mar 2006
    Location
    Rainham, Essex.
    Posts
    5
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Limit Logon VBS Version

    Quote Originally Posted by Snuffkins
    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.

  2. #17
    Snuffkins's Avatar
    Join Date
    Jan 2006
    Posts
    207
    Thank Post
    14
    Thanked 8 Times in 8 Posts
    Rep Power
    23

    Re: Limit Logon VBS Version

    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...

  3. #18
    steve's Avatar
    Join Date
    Oct 2005
    Location
    West Yorkshire
    Posts
    1,047
    Thank Post
    22
    Thanked 178 Times in 124 Posts
    Rep Power
    53

    Re: Limit Logon VBS Version

    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:
    Code:
    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:

    Code:
    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?

  4. #19

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,691
    Thank Post
    756
    Thanked 1,715 Times in 1,526 Posts
    Rep Power
    438

    Re: Limit Logon VBS Version

    How about something like:

    Code:
    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

  5. #20
    steve's Avatar
    Join Date
    Oct 2005
    Location
    West Yorkshire
    Posts
    1,047
    Thank Post
    22
    Thanked 178 Times in 124 Posts
    Rep Power
    53

    Re: Limit Logon VBS Version

    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

  6. #21
    alonebfg's Avatar
    Join Date
    Aug 2006
    Location
    south west some of the time
    Posts
    834
    Thank Post
    12
    Thanked 34 Times in 21 Posts
    Blog Entries
    5
    Rep Power
    24

    Re: Limit Logon VBS Version

    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.

  7. #22

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,053
    Thank Post
    3,586
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377

    Re: Limit Logon VBS Version

    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/scr...6/hey0727.mspx

  8. #23
    edie209's Avatar
    Join Date
    Mar 2006
    Location
    Kernow
    Posts
    705
    Thank Post
    42
    Thanked 19 Times in 18 Posts
    Rep Power
    22

    Re: Limit Logon VBS Version

    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

    Code:
    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

    Code:
    Set filetxt = objFSO.OpenTextFile(strpathname & "logs\" & formatdatetime(Now(),vblongdate) & ".log", 8, True)
    and the machine remains logged on.

    here is the full logon script

    Code:
    '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

  9. #24
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,007
    Thank Post
    124
    Thanked 286 Times in 263 Posts
    Rep Power
    109

    Re: Limit Logon VBS Version

    Is your server actually called "server" ?

  10. #25
    edie209's Avatar
    Join Date
    Mar 2006
    Location
    Kernow
    Posts
    705
    Thank Post
    42
    Thanked 19 Times in 18 Posts
    Rep Power
    22

    Re: Limit Logon VBS Version

    no my server is named invincible, I have changed that but I just edited it to make it easier on the forum.

  11. #26
    edie209's Avatar
    Join Date
    Mar 2006
    Location
    Kernow
    Posts
    705
    Thank Post
    42
    Thanked 19 Times in 18 Posts
    Rep Power
    22

    Re: Limit Logon VBS Version

    I'm still struggling with this problem and VBS is not a strong part for me in fact I know didly squat.

    SO I have posted the same question on a VBS forum and got some replies

    CaSE matters here. Try this.

    At line 35: StrUserName = lcase(WSHNetwork.UserName)
    at line 41: If ((StrUserName = "cybercafe") OR (StrUserName = "ils")) Then

    I troubleshoot issues like this by echoing out what is going into the IF then echo what has actually made it into the IF.
    Example
    Code:
    wscript.echo that
    If this=that then
      wscript.echo "made it into if"
    Else
      wscript.echo "made it into else"
    End if
    I hope this helps.
    and

    If the pathname is wrong try sending it to a msgbox and double check that the filename that you are setting is correct msgbox strpathname & "logs\" & formatdatetime(Now(),vblongdate) & ".log"
    Sometimes I find that there is a slash I left out.
    I tried the CaSe but that didn't work as to the other suggestion could someone tell me what that they are asking me to do.

  12. #27

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,053
    Thank Post
    3,586
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377

    Re: Limit Logon VBS Version

    at the start of the script where you have the constants , have you changed the share name from :

    Const Share_Name = "limitlogon$"

    to a sharename that you have on your invincble server ?

    Also for the other suggestion he gave you the code to try out which was :

    msgbox strpathname & "logs\" & formatdatetime(Now(),vblongdate) & ".log"

    and he is basically saying to use that instead of trying to write that to a text file as per here :

    '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 you have any other chunks of code that uses the same code with regards to creating a text file in this manner then I would suggest you check the paths of them as well using a messagebox so that it prompts you with the full path including the filename , slashes etc, that way you can see for yourself if the path is correct.

  13. #28
    edie209's Avatar
    Join Date
    Mar 2006
    Location
    Kernow
    Posts
    705
    Thank Post
    42
    Thanked 19 Times in 18 Posts
    Rep Power
    22

    Re: Limit Logon VBS Version

    I have spent far too many hours on this now but I thnk I might be getting somewhere.

    If I have the share name as limilogon$ I get an error on line 130 char 3 path not found on PC1

    then when I log on to PC2 I get the mesage box informing me that I am already logged on elsewhere and that i will be logged off on clicking the OK button I then get another error on line 91 char 6 path not found.

    HOWEVER

    If I rename the share to limitlogon and change the referances in the script to suite I get a different error....
    I log onto PC1
    and get this error 121 char bad file name or number 800A0034

    when I log onto PC2 I get the same error but I don't get the message box telling me I'm already logged on

    Any ideas..... anyone have a working script for limit logon that logs the user off?

  14. #29

    Join Date
    Feb 2007
    Location
    Hereford
    Posts
    213
    Thank Post
    5
    Thanked 3 Times in 3 Posts
    Rep Power
    16
    I'm looking for a solution to do this job.
    I've come accross

    UserLock: Access security and control for Windows networks

  15. #30

    Join Date
    Aug 2009
    Location
    Brisbane
    Posts
    2
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    issue if PC is not shut down properly?

    The issue i have with this script is when a user resets their PC (or there is another issue where the PC resets itself) and the log off action does not occur. This would result in a Service Desk job to remove the file or db entry wouldnt it?

    k



SHARE:
+ Post New Thread
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Printer limit
    By pedster666 in forum Hardware
    Replies: 10
    Last Post: 5th December 2007, 01:35 PM
  2. Limit Logon Woes..
    By Gatt in forum Windows
    Replies: 1
    Last Post: 6th November 2007, 01:55 PM
  3. Limit Login
    By faza in forum How do you do....it?
    Replies: 7
    Last Post: 19th July 2007, 04:48 PM
  4. Terminal Server - limit which computers can be used to logon
    By broc in forum Thin Client and Virtual Machines
    Replies: 5
    Last Post: 26th June 2007, 03:21 PM
  5. limit login
    By whatwherewhen in forum Network and Classroom Management
    Replies: 12
    Last Post: 20th February 2007, 07:29 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •