With WSH you can create automated login scripts. The following example assumes that a company has two file servers (named "server1" and "server2"), and two print servers (named "printer1" and "printer2"). To balance usage of the servers, everyone whose login name starts with A - K goes to the first file and print server, and everyone whose login name starts with L - Z goes to the second one.
Example
Note |
---|
In Windows 9x, include a delay so user logon takes affect. |
Copy Code | |
---|---|
// JScript. var oNet, sUser, cInitial, startTime; oNet = new ActiveXObject("WScript.Network"); // Get the user name. On Windows 98 and Windows ME, the user may not be // logged on when the script starts running; keep checking every 1/2 a // second until they are logged on sUser = oNet.UserName; startTime = new Date(); while (sUser == "") { var curTime = new Date(); if (curTime – startTime > 30000) WScript.Quit(); WScript.Sleep(500); sUser = oNet.UserName; } // Add a share for the "h" drive and the printer, based on the // first letter of the user's name cInitial = sUser.charAt(0).toUpperCase(); if (cInitial < "L") { oNet.MapNetworkDrive("h:", "\\\\server1\\users\\" + sUser); oNet.AddWindowsPrinterConnection("\\\\printer1\\hp", "HP LaserJet 4"); } else { oNet.MapNetworkDrive("h:", "\\\\server2\\users\\" + sUser); oNet.AddWindowsPrinterConnection("\\\\printer2\\hp", "HP LaserJet 4"); } ' VBScript. Option Explicit Dim oNet, sUser, cInitial, startTime ' Helper object Set oNet = CreateObject("WScript.Network") ' Get the user name. On Windows 9x, the user may not be logged ' on when the script starts running; keep checking every 1/2 a ' second until they are logged on. sUser = oNet.UserName startTime = Now Do While sUser = "" If DateDiff("s", startTime, Now) > 30 Then Wscript.Quit Wscript.Sleep 500 sUser = oNet.UserName Loop ' Add a share for the "h" drive and the printer, based on the ' first letter of the user's name cInitial = UCase(Left(sUser, 1)) If (cInitial < "L") Then oNet.MapNetworkDrive "h:", "\\server1\users\" & sUser oNet.AddWindowsPrinterConnection "\\printer1\hp", "HP LaserJet 4" Else oNet.MapNetworkDrive "h:", "\\server2\users\" & sUser oNet.AddWindowsPrinterConnection "\\printer2\hp", "HP LaserJet 4" End If |