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.
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...
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?
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
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
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.
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
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
Re: Limit Logon VBS Version
Is your server actually called "server" ?
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.
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
Quote:
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
Quote:
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.
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.
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?
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