sloughman Posted March 26, 2015 Posted March 26, 2015 Hello all, I would like to make a small amendment to the following script (taken from elsewhere on Edugeek) which logs users off if a mapped network drive is not present. I currently use this, however as mapped drives can take a while to appear on my network after desktop appears especially on laptops, I have to build in quite a long sleep time before script runs. What I would like to amend it to do is to log off user if the C drive is visible NOT if a mapped drive is not present I then could make it a much shorter sleep time if a student somehow manages to bypass normal log on. I am no scripter so any help will be gratefully received . 'check for unplugged network cord during logon 'checks for mapped drives 'merge registry key to run '| Windows Registry Editor Version 5.00 '| [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] '| "check-home-dir"=""C:\\WINDOWS\\whlogoff.vbs"" 'copy this vbs file to c:\windows directory Option Explicit ' Added By SM Dim objNetwork Dim strUserName Dim WshShell, WshNetwork, ObjFSO Dim intReturn Set objNetwork = CreateObject("WScript.Network") Set WshShell = CreateObject("WScript.Shell") Set WshNetwork = CreateObject("WScript.Network") Set ObjFSO = CreateObject("Scripting.FileSystemObject") ' Wait until the user is really logged in... Added by SM While StrUserName = "" WScript.Sleep 30000 ' 30 seconds StrUserName = WSHNetwork.UserName ' Get the user name Wend if strUserName = "Administrator" then 'Ignore the admins ;-) Added By SM else 'Check if the home drive is there... Added By SM if ObjFSO.DriveExists("m:") then 'Yes it is bail out... Added By SM else 'No its not, has the network cable been pulled... Added By SM intReturn = WshShell.Popup("Please ensure the network Cable is plugged in or the Wireless Button is on.", 8, "Login Error", 0) If intReturn = 1 Then ' Trap the button click... Added By SM 'Wscript.Echo "You clicked the ok button. This would log you off" WshShell.Run "logoff.exe" Else ' The popup timedout log the user off... Added By SM 'Wscript.Echo "The popup timed out. This would log you off after a timeout" WshShell.Run "logoff.exe" End If End if End if
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now