Solved

VBS Logon Script that maps network drives based on username.

Posted on 2004-08-04
3
557 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

FIPS stands for the Federal Information Processing Standardisation and FIPS 140-2 is a collection of standards that are generically associated with hardware and software cryptography. In most cases, people can refer to this as the method of encrypti…
This article is in response to a question (http://www.experts-exchange.com/Networking/Network_Management/Network_Analysis/Q_28230497.html) here at Experts Exchange. The Original Poster (OP) requires a utility that will accept a list of IP addresses …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now