Solved

Script to Map Network Drives

Posted on 2013-01-24
8
685 Views
Last Modified: 2013-02-11
I'm trying to write a batch file that will automatically map network drives upon restart of a number of workstations running Windows7, Vista, or XP.  

There are lots of postings on this topic in EE and elsewhere.  It appears very straightforward, although I have absolutely no prior experience with this stuff.  See the following as an example:  http://community.spiceworks.com/how_to/show/1487-how-to-create-a-batch-file-for-network-drive-mapping.

I followed the instructions above:
1.  Open notepad.
2.  Typed the following:  net use G:\\servername\D
3.  Saved file as a .bat (NOT a .txt file)

To test it, I simply saved it on my desktop and double-clicked it to run it.  I expected it to create a mapped network drive with letter designation "G".  It doesn't appear that it did anything.

I've tried running it on both Windows 7 and Vista.  I've also tried running it as administrator.  No joy.

Ultimately, I would like this batch file to map multiple drives from all the computers in my office.  

Any help would be greatly appreciated.

thanks,
darin
0
Comment
Question by:DarinOBrien
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 5

Accepted Solution

by:
Harsem earned 350 total points
ID: 38816593
Hello,

that syntax is almost correct - and you also have to make sure that the drive is shared. Windows has a number of default administrative shares, but they are hidden.

To access these administrative shares you can use:

net use G: \\servername\D$
(note the space between  the ":" & "\\")

However I think it would be better if you shared a folder on the server (Servername) and then you can access it via:

net use G: \\servername\Folder

Hope this helps

Jens
0
 
LVL 26

Expert Comment

by:pony10us
ID: 38816658
Microsoft is good at giving help for commands:


The syntax of this command is:

NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
        [/USER:[domainname\]username]
        [/USER:[dotted domain name\]username]
        [/USER:[username@dotted domain name]
        [/SMARTCARD]
        [/SAVECRED]
        [[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

NET USE [/PERSISTENT:{YES | NO}]


As for a batch file you are correct to save it as a ".bat"

@echo off
net use g: \\servername\Folder /persistent:yes

Open in new window

0
 

Author Comment

by:DarinOBrien
ID: 38816696
The space between the ":" and the "\\" was the problem!

I'm actually trying to map a drive to a shared folder on the server ("D").  It's not hidden so I assume it's not an administrative share?
 
Can you also please tell me how to make this batch file first delete ALL mapped network drives that might be on the workstation?  Alternatively, it would probably work to delete any existing shares with the same letter designation (e.g. I want to create a new share "G" so I want to delete and pre-existing shares "G").

Lastly, can you tell me where to place this batch file so that it runs automatically everytime the users restart their computers?  Again, working with XP, Vista and Windows7 so maybe they're different locations?

Thanks!
darin
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 2

Assisted Solution

by:beefstu123
beefstu123 earned 50 total points
ID: 38816714
Hi,
here is another way to do it using IP address:

EG:

net use G: \\192.168.0.121\[folder name]

also does the server have a password if it does you have to apply it to your bat file:

net use G: \\192.168.0.121\[folder name] /user:[username] [password]
Note there is a space between the username and the password

EG:

net use G: \\192.168.0.121\folder1 /user:admin1 user1
admin1 is the username and user1 would be the password

and adding another location is just adding another line to your bat file, save and test.
To check if your folders are shared just type the server ip address in to a folder address bar
EG: \\192.168.0.121
and it will show what you have shared on that system
Note: you will have to setup static IP addresses for the server and any other system that are hosting the shared files if you dont' you will have to get the ip address every time the server restarts, to resolve this use Harsem's method and use the system name instead of the ip address.

Once that is done all you have to do is to add it to start up folder and it will run every time you system starts up (put a copy on the desktop as well sometimes the network hasn't been detected when start up tries to run the bat file)

hope it works
beefstu123
0
 
LVL 5

Assisted Solution

by:Harsem
Harsem earned 350 total points
ID: 38816746
Hello,

to remove a share is easy:
net use /d g:

I do not know how to delete all, but that will remove G:

To automatically run that is easy:
(from www.computerhope.com/issues/ch000322.htm )  
Windows 98, XP, NT, 2000, Vista and later users

    Create a shortcut to the batch file.
    Once the shortcut has been created right-click the file and select Cut.
    Click Start, Programs, right-click the Startup folder and click Open
    Once the Startup folder has been opened click Edit and paste the shortcut into the startup. Any shortcuts in the startup folder will automatically start each time Windows starts.

Hope this helps

Jens
0
 
LVL 26

Expert Comment

by:pony10us
ID: 38816869
If the computers are on a Active Directory domain then you could place the commands in the login script or push via GPO.
0
 
LVL 77

Assisted Solution

by:Rob Williams
Rob Williams earned 100 total points
ID: 38816903
A good idea is to disable persistent mappings and delete all existing mappings before creating new mappings to assure there are no conflicts with exiting mappings or ones created by users.  To do so use something similar to:

Net Use /persistent:no
Net Use * /delete
Net Use X: \\ServerName\ShareName1
Net Use Y: \\ServerName\ShareName2
Net Use Z: \\ServerName\ShareName3

You may also wish to review the following article as to how to apply the mappings, if you have a domain.  A more common practice today is group Policy preferences, but that is not 100% effective with XP machines.  The article also discusses other options:
http://blog.lan-tech.ca/2012/03/01/dive-mapping-basics/
0
 

Author Closing Comment

by:DarinOBrien
ID: 38877397
I used harsem solution first shown above:

net use G: \\servername\Folder

In combination with a bunch of these to delete all prior mapped network drives:

net use /delete X:

I avoided using IP addresses for fear that they would change.


Thanks to everyone who participated.  I especially appreciate the link to detailed reference material.

darin
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

759 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