Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 698
  • Last Modified:

Script to Map Network Drives

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
DarinOBrien
Asked:
DarinOBrien
  • 2
  • 2
  • 2
  • +2
4 Solutions
 
HarsemCommented:
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
 
pony10usCommented:
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
 
DarinOBrienAuthor Commented:
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
beefstu123Commented:
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
 
HarsemCommented:
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
 
pony10usCommented:
If the computers are on a Active Directory domain then you could place the commands in the login script or push via GPO.
0
 
Rob WilliamsCommented:
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
 
DarinOBrienAuthor Commented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now