Jump to content

Recommended Posts

Posted (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 by ChrisH
Posted

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

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

Posted

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

Posted
@Russ: That goes without saying. Something along the lines of " tried to log onto whilst logged onto - like that's going to happen! Fool!"?
Posted

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

Posted

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

  • 2 months later...
Posted
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 :?
Posted

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

  • 4 months later...
Posted

Just had a quick scan and that looks very good :D 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 :?

Posted

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

Posted

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

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

Posted

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

  • 7 months later...
Posted

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?

Posted

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

  • 4 weeks later...
Posted

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

Posted
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.
  • 2 months later...
Posted

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

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



×
×
  • Create New...