Solved

I need a script that will automatically map drives at login.

Posted on 2009-03-29
5
378 Views
Last Modified: 2012-05-06
I need a script that will automatically map drives at login.  The script will be used only on a specific terminal server and users, I don't want to setup a gpo.  I want the script to be seamless to the user and non-persistent, I don't want the mapped drives to be saved to their profile.  The script should resume on error for any customer that is having any permission problems.  Can I use the usrlogin.cmd script, would that work or would I need a vbs script?
I would like the following mapped drives for all users accessing this particular server.
k:=\\server1\test
m:=\\server2\test2
o:=\\server3\test3

Can anyone help me with this problem.

Thanks!
0
Comment
Question by:mystikal1000
5 Comments
 
LVL 6

Expert Comment

by:ITHelper80
ID: 24013903
You can use a .batch  file and put it in the startup folder.
Use the syntax below in a text file and save it as "filename".bat

Syntax for mapping a network drive:
NET USE devicename \\computername\sharename /PERSISTENT:{YES|NO}
devicename  - are any unused drive from D: through Z:
persistent - yes means "reconnect at logon" and no means don't "reconnect at logon"
Examples:
NET USE U: \\lf111-server\data\users /PERSISTENT:NO
maps the U: drive to the users share and without reconnecting at next logon
NET USE F: \\lf111-server\data /PERSISTENT:YES
maps the F: drive to the data share and reconnects F: to it at subsequent logons
0
 
LVL 6

Expert Comment

by:ITHelper80
ID: 24013908
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24014385
If you want the drives mapped for all users, and it's just one server, then modifying usrlogon.cmd will be fine.  Or even, leave your code in \\MYDC\NetLogon\TSLogon.cmd, and just add
Call \\MYDC\NetLogon\TSLogon.cmd

to usrlogon.cmd on that server.  Then, the below would be the contents of TS_Logon.cmd

@echo off
NET USE K: \\server1\test /PERSISTENT:NO
NET USE M: \\server2\test2 /PERSISTENT:NO
NET USE O: \\server3\test3 /PERSISTENT:NO

Regards,

Rob.
0
 
LVL 2

Accepted Solution

by:
supportemea earned 500 total points
ID: 24017821
Here ya go
Option Explicit

Dim objNetwork, strRemotePath1, strRemotePath2, strRemotePath3, strRemotePath4

Dim strDriveLetter1, strDriveLetter2, strDriveLetter3, strDriveLetter4
 
 

strDriveLetter1 = "z:" 

strDriveLetter2 = "x:" 

strDriveLetter3 = "y:"

strDriveLetter4 = "w:"
 

strRemotePath1 = "\\fileserver\share1" 

strRemotePath2 = "\\fileserver\share2"

strRemotePath3 = "\\fileserver\share3"

strRemotePath4 = "\\fileserver\share4"

on error resume next
 
 

Set objNetwork = CreateObject("WScript.Network") 
 
 

objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1

objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2

objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3

objNetwork.MapNetworkDrive strDriveLetter4, strRemotePath4
 

WScript.Quit 

Open in new window

0
 
LVL 9

Expert Comment

by:unassassinable
ID: 24057286
Here is the how to so you can learn for yourself directly form Microsoft Technet:

http://technet.microsoft.com/en-us/library/cc758918.aspx
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

13 Experts available now in Live!

Get 1:1 Help Now