+ Post New Thread
Results 1 to 4 of 4
Scripts Thread, Stop multiple log ins in Coding and Web Development; Hi Ive got the following script to stop multiple logons by studnets - it creates a file based on pc ...
  1. #1

    Join Date
    Mar 2014
    Location
    scunthorpe
    Posts
    14
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Question Stop multiple log ins

    Hi

    Ive got the following script to stop multiple logons by studnets - it creates a file based on pc name and username. If they log off properly, it deletes it, if they dont, it wont and either i have to delete it, they have to log back onto their previous machine and log off again or someone else has to log onto that machine. I didnt make the script but it does everything i want. The issue is the shutdown part (BELOW) gives me a bad file name error and i dont know why - it looks ok.

    This is the segment

    'Shutdown Process'
    shutdown = "shutdown /l"
    WshShell.Popup _
    "You are already logged onto: " & CurrentWorkstation & " or havent logged off properly." & vbcrlf & _
    "This event has be logged to track possible account misuse." & vbcrlf & vbcrlf & _
    "You will now be logged off",20,"Multiple User Login Detected: " & UserID,16
    WshShell.Run "C:\windows\system32\shutdown.exe"
    SET WshShell = Nothing


    and this is the full script.

    '== Limit User Logins
    '== This script consists of two parts, UserLogon.vbs & UserLogoff.vbs
    '== The script is designed to prevent multiple logons on a network from different workstations
    '== This will not work for Terminal Servers where each user will login on the same server.
    '== Users NEED to logoff through the proper process otherwise the script will still assume they are logged in.
    '== If this happens, then the next user to log into their workstation will clear their session


    'Set Objects
    Set oShell = CreateObject( "WScript.Shell" )
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    SET WshShell = createObject("WScript.shell")
    Const intForReading = 1
    Const intForWriting = 2
    Const intForAppending = 8
    ServerShare = "\\sfoxfilepr1\logonfiles$" 'Requires Users Full Read/Write Access
    OldSession = ""
    CurrentWorkstation = ""


    'Get Username & Workstation
    UserID=oShell.ExpandEnvironmentStrings("%UserName% ")
    WorkstationID=oShell.ExpandEnvironmentStrings("%Co mputerName%")


    'Check Whether Workstation Has Old Login Session and clear


    If objFSO.FileExists( ServerShare & WorkstationID & ".txt") Then
    Set objFile = objFSO.OpenTextFile(ServerShare & WorkstationID & ".txt", intForReading, False)
    Oldsession = objFile.ReadLine
    objFile.Close
    If objFSO.FileExists( Servershare & Oldsession & ".txt" ) Then
    objFSO.DeleteFile(ServerShare & Oldsession & ".txt")
    End if
    End if

    'Check If Users Logged In
    If objFSO.FileExists ( ServerShare & UserID & ".txt") then
    Set objFile = objFSO.OpenTextFile(ServerShare & UserID & ".txt", intForReading, False)
    CurrentWorkstation = objFile.ReadLine
    objFile.Close

    'Report Failed Login To LoginsDenied.log


    If objFSO.FileExists (ServerShare & "LoginsDenied.log") then


    SET ObjFile = objFSO.OpenTextFile(ServerShare & "LoginsDenied.log", intForAppending, True)
    ObjFile.Writeline ("Date: " & Date & ", Time: " & Time & ", Workstation: " & WorkstationID & ", Username: " & UserID)


    else
    Set objFile = objFSO.CreateTextFile(ServerShare & "LoginsDenied.log")
    ObjFile.Writeline ("Date: " & Date & ", Time: " & Time & ", Workstation: " & WorkstationID & ", Username: " & UserID)


    End If


    ObjFile.Close


    'Shutdown Process'
    shutdown = "shutdown /l"
    WshShell.Popup _
    "You are already logged onto: " & CurrentWorkstation & " or havent logged off properly." & vbcrlf & _
    "This event has be logged to track possible account misuse." & vbcrlf & vbcrlf & _
    "You will now be logged off",20,"Multiple User Login Detected: " & UserID,16
    WshShell.Run "C:\windows\system32\shutdown.exe"
    SET WshShell = Nothing

    Else


    'Create Text Files
    Set objFile = objFSO.CreateTextFile(ServerShare & WorkstationID & ".txt")
    ObjFile.Write(UserID)
    ObjFile.Close
    Set objFile = objFSO.CreateTextFile(ServerShare & UserID & ".txt")
    ObjFile.Write(WorkstationID)
    ObjFile.Close


    'Report Accepted Login To LoginsAllowed.log
    If objFSO.FileExists (ServerShare & "LoginsAllowed.log") then


    SET ObjFile = objFSO.OpenTextFile(ServerShare & "LoginsAllowed.log", 8, True)
    ObjFile.Writeline ("Date: " & Date & ", Time: " & Time & ", Workstation: " & WorkstationID & ", Username: " & UserID)


    else
    Set objFile = objFSO.CreateTextFile(ServerShare & "LoginsAllowed.log")
    ObjFile.Writeline ("Date: " & Date & ", Time: " & Time & ", Workstation: " & WorkstationID & ", Username: " & UserID)


    End If


    ObjFile.Close



    End If

    It all looks ok but the error is

    Line 67
    Char 2
    Error Bad file name or number
    Code 800A0034

    Thanks

    Steve

  2. #2

    Join Date
    Feb 2009
    Posts
    149
    Thank Post
    0
    Thanked 36 Times in 35 Posts
    Rep Power
    18
    'Shutdown Process'
    shutdown = "shutdown /l"
    WshShell.Popup _
    "You are already logged onto: " & CurrentWorkstation & " or havent logged off properly." & vbcrlf & _
    "This event has be logged to track possible account misuse." & vbcrlf & vbcrlf & _
    "You will now be logged off",20,"Multiple User Login Detected: " & UserID,16
    WshShell.Run "C:\windows\system32\shutdown.exe"
    SET WshShell = Nothing
    The first line (shutdown = "shutdown /l") doesn't appear to be doing anything so could be removed and the WshShell.Run command needs a switch adding (ie: WshShell.Run "C:\windows\system32\shutdown.exe /l". Alternatively leave the shutdown = line in and change the WShShell.Run line to 'WshShell.Run shutdown'.

  3. #3

    Join Date
    Mar 2014
    Location
    scunthorpe
    Posts
    14
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Quote Originally Posted by HilcrRWise View Post
    The first line (shutdown = "shutdown /l") doesn't appear to be doing anything so could be removed and the WshShell.Run command needs a switch adding (ie: WshShell.Run "C:\windows\system32\shutdown.exe /l". Alternatively leave the shutdown = line in and change the WShShell.Run line to 'WshShell.Run shutdown'.

    Changed to



    'Shutdown Process'
    WshShell.Popup _
    "You are already logged onto: " & CurrentWorkstation & " or havent logged off properly." & vbcrlf & _
    "This event has be logged to track possible account misuse." & vbcrlf & vbcrlf & _
    "You will now be logged off",20,"Multiple User Login Detected: " & UserID,16
    WshShell.Run "C:\windows\system32\shutdown.exe /l"
    SET WshShell = Nothing


    Line 66 Char 2 - Shutdown line removed as recommended so looking at the same line.

    Thanks

  4. #4

    Join Date
    Mar 2014
    Location
    scunthorpe
    Posts
    14
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0
    FYI i still got the same error? Im on a 64 bit OS but that shouldn't make any odds for the shut-down command?

    Thanks

    Steve

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 14
    Last Post: 12th July 2011, 07:51 PM
  2. MRBS - Stopping students from logging in and making bookings?
    By Sam_Brown in forum Network and Classroom Management
    Replies: 8
    Last Post: 18th May 2011, 10:13 AM
  3. [CLOSED] Bug/Error: multiple log in
    By leco in forum EduGeek.net Site Problems
    Replies: 6
    Last Post: 18th April 2009, 07:34 PM
  4. Stop Users Logging In to Domain
    By moggy in forum Windows Server 2000/2003
    Replies: 7
    Last Post: 17th December 2008, 04:05 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
  •