All Forums >> [Scripting] >> Post a VBScript >> Stop Multiple Windows Logins Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
'"Multiple Logons a problem? Not anymore!!" - By Amfony ' 'This is my vbscript interpretation of a batch script that will stop multiple logons in a windows environment (with logon and logoff scripts) ' ' 'Requirements for script to work: ' 'A server with a shared folder named "logons" everyone full access (for easiness of implementation) 'A Folder within the share folder "logons" named "SecondAttempt" 'A XL file named "duplicates.xls" with lines of DATA (being Anything) in the 4th and 5th row (Because ammending XL is a biiiiyatch) 'A XL file named "Status.xls" with 2 lines of DATA (being Anything) in the 4th and 5th row (refer above) ' 'These XL files need to be on the \\server\logons share ' ' 'Pseudo Code ' 'The idea of this code is to have a user when logging on create a file/folder object based on their username on a share folder on a server. Then incorporate in the script an IF EXists 'statement to forecfully log the user off if there is already a file/folder object with that same Username name. ' 'My code however will record to XL files everytime a user logs on successfully (write to status.xls), or unsuccessfully (write to duplicates.xls), also in addition to the username, 'computername, time and date at that the event occured. My code will also write the event time details INSIDE the file it created based on username, which it will then read from 'to display a popup box with variables about the user,computer loggedinto and so forth if there is a secondlogon attempt. ' 'My script will upon second logon, create a second text file named "\\SERVER\logons\secondAttempt\second%username%.txt" that it will then incorporate into my 'logoff.vbs script (REFER BELOW)
' 'The story with the logoff script is quite simply ' 'If the file "\\SERVER\logons\secondattempt\second%username%.txt" EXIST (which inturn means that there was a concurrent connection, a multiple logon was attempted, and that 'this logoff procedure is forced {not by choice} ' 'THEN delete the "\\SERVER\logons\secondattempt\second%username%.txt" File (clean up duty) 'and then proceed to send.keys "logoff.exe" to the shell. ' ' 'IF However the " \\... second%username%.txt DOES NOT EXIST 'THEN ' 'Call gracefulexit function which will delete the "\\SERVER\logons\%username%.txt file. (Leaving the user free to log on again anywhere/time they wish.) ' '
Dim strUsername, del, secondattemptFile, file Set fso = CreateObject("Scripting.FileSystemObject") Set net = createobject("Wscript.network") Set wshell = CreateObject("wscript.Shell")
End If '---------------------------------------------------------- Function SecondAttemptExit(SecondAttemptDel) FSO.deletefile(SecondAttemptDel) wshell.run "logoff.exe" End Function Function GracefulExit(GracefulDel) fso.deletefile(GracefulDel) wshell.run "logoff.exe" End Function
< Message edited by Snipah -- 9/16/2005 6:20:15 AM >