Scripts Thread, vbs logon with ie in Coding and Web Development; here is a logon script i use
origionally from
Mark Minasi's Reader Forum - VBS & IE Logon Script:
but ...
function checkKey(){
if (window.event.keyCode == 13){
window.event.keyCode = 0;
sayHello("form1","http://2063-fs01/exchange");
}
}
function sayHello(theForm, theUrl){
// Define local variables and initialise
var theUrl = theUrl;
var theForm = eval("document." + theForm + "");
var theUser = theForm.username.value;
I was wondering if it was possible to edit the vbs so that it closed after a short timeout(as it does now) if there were no errors, but either writing an error log to a file on the server or staying open with a message if one/all of the checks fail.
I have very little idea of what to change as I have only just started looking into vb scripting but i'm sure that some of the clever people on here would be able to knock it up in a few minutes.
Just thought it may help for when we get a message saying little johnny couldnt access his work/shared area but no-one actually knows which bit or why.
'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\Curr entVersion\Run]
'| "check-home-dir"="\"C:\\WINDOWS\\vbs_logoff.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 100 ' 1/10 th of a second
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("W:") 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"
I had this issue a while back (the network plug being unplugged etc), kids were doing it after login to stop us remoting in etc. I found that the .Net framework as an event which is triggered when the network availability has changed:
Code:
System.Net.NetworkInformation.NetworkChange.NetworkAvailabilityChanged += new System.Net.NetworkInformation.NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
void NetworkChange_NetworkAvailabilityChanged(object sender, System.Net.NetworkInformation.NetworkAvailabilityEventArgs e)
{
if (e.IsAvailable)
{
// We're back on...
onNetworkConnected();
}
else
{
// We've been unplugged... logout...
onNetworkDisconnected();
}
}
I'll post a full C# example later which will sit in the background and watch if wanted?
If IsMember("Admins") Then
showstat("Mapping S: for Sims")
If Not MapDrive("S:", "\\server\sims") Then
showstat "Error, Unable to Map S: to Sims"
End If
End if