Solved

VBS Logon Script that maps network drives based on username.

Posted on 2004-08-04
3
567 Views
Last Modified: 2010-08-05
Greetings all,

Does anyone have a sample logon script that maps network drives based on user name.

Eg if username between a-k then map n: = server1
    if username between l-z then map n: = server2

0
Comment
Question by:tallemu
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
marc_nivens earned 150 total points
ID: 11720890
Something like this should work:

set objNet = CreateObject("Wscript.Network")
select case left(objNet.UserName,1)
      
      case "A","a","B","b"    'keep going to k
            'code to map to server 1
                case "L","l","M","m"    'keep going to z
                                'code to map to server 2

End Select
0
 

Author Comment

by:tallemu
ID: 11724199
Do you have a working example of this logon script?
0
 

Author Comment

by:tallemu
ID: 11724596
I have found the answer on microsofts website

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsconcreatingautomatingloginscrip.asp

Here is the vbs logon script example

// JScript.
var oNet, sUser, cInitial, startTime;
oNet = new ActiveXObject("WScript.Network");
// Get the user name. On Windows 98 and Windows ME, the use 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 use 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
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Enterprise networks where VoIP phones have been deployed frequently use port configurations that allow both a computer and an IP phone to be plugged into the same switch port but use different VLANs. On Cisco equipment I'm referring to the "native V…
Resolve DNS query failed errors for Exchange
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question