Batch Files - Drive Mapping
Introduction: This article expands on what you've already learnt in the basics article. After reading this, you should be able to write a batch file to automatically map a network drive (or several) automatically.
Mapping a network drive can easily be done using the Tools menu on My Computer. But this can be time consuming, especially if you've got to map several drives, and can't remember the full network addresses. Read on if you want to know more...
The commands: If you've read the Defrag article, then you'll already know how to use output. If not - go read it first!
The following line does all of the hard work in this batch file:
net use m: \fileserver\m$
I use this in a batch file at home. It maps the m drive on my fileserver to my laptop's m drive. This is a must for my iTunes setup, as I have over 50gb of music stored on the fileserver, which is more than my laptop HDD can hold. I manipulate the iTunes library on my fileserver to organise my music and playlists, and this library is also stored on my laptop. Assigning the fileserver's MP3 drive (m:) to a network drive on my laptop tricks iTunes into thinking that the music is on my laptop. Confusing I know, but you'll understand it with a bit of practice.
Now, what does the line mean? Well, take the first part:
net use m:
It's asking Windows to use the m: drive. When you come to write your own batch file, replace m: with the drive you wish to be used in the mapping. So for example, if you wanted to map the f: drive to your computer's g: drive, then put g: here instead of m:
The next part states:
Which is the network address of the network computer's drive that you wish to use in the mapping. Replace this as needed.
Practical use: Your computer is named computerA, the network computer that you'll be using for the drive mapping is computerB. You wish to map computerB's E drive to computerA's F drive. This is how the command will look:
net use f: \computerB\e$
This example should have clarified the previous ramblings, so put it to use and see if you can map a network drive successfully.
Sharing and Permissions: Those of you in the know would have spotted that I use administrator shares to map drives:
These will only work if you've setup two identical users on both machines, each with the same password. If you wish to use normal shares, then you can simply right click on a drive you wish to be mapped via the network, and choose Sharing. Then it's a case of enabling sharing for the drive - in XP you'll have to ignore the risks of sharing a root drive message.
To find out the administrator shares on a machine, right click on My Computer on the desktop, and choose Manage. Then navigate to Shares and it will list all current shares on the computer. Here you'll spot the various administrator shares, highlight with a dollar sign ($).
Check out the Windows Sharing article for further information.
Conclusion: If you've followed this article correctly, then you should be well on your way to setting up a mapped network drive or two. I've uploaded an example here - feel free to use it for reference. It successfully maps my fileserver's hard-drives to my laptop. Once you've made your batch file and tested to ensure it works correctly, you can either schedule it, or put it in your startup folder for ease of use.
There are 3 comments: