Jump to content

Recommended Posts

Posted

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("%ComputerName%")

 

 

'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

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

Posted
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

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