Windows

Use the PushD command to create a quick temporary drive map in Windows XP

You can use the PushD command to quickly create a temporary drive map while remaining in the Command Prompt, saving time and unnecessary keystrokes. Greg Shultz reveals how it works.

Have you ever been working from a Command Prompt and needed to temporarily map a drive letter to a network location for a quick file operation? Of course, you can switch over to Windows Explorer and use the Map Network Drive command on the Tools menu.

While this is a viable solution, it requires multiple steps to create and then you have to perform several more steps to disconnect the network drive. This can be a pain -- especially if you just want to work from a Command Prompt.

However, there is another way. You can use the PushD command to quickly create a temporary drive map while remaining in the Command Prompt. You can then use PopD to quickly disconnect the network drive. Here's how:

  1. Open a Command Prompt window.
  2. Type the following command line:
    PUSHD ServerSharepath
    where \\Server\Share\path is the network resource to which you want to map a drive letter.

As soon as you do, the PUSHD command will instantly map a drive letter to the network resource and then change to that drive right in the Command Prompt window. When you're done, just type POPD and the mapped drive letter will be disconnected and you'll return to your original drive.

Keep in mind that, the PUSHD command allocates drive letters from Z: on down and will use the first unused drive letter that it finds.

Note: This tip applies to both Windows XP Home and Windows XP Professional.

Miss a Windows XP tip?

Check out the Windows XP archive, and get more hands-on Windows XP tips.

Stay on top of the latest XP tips and tricks with our free Windows XP newsletter, delivered each Thursday. Automatically sign up today!

About

Greg Shultz is a freelance Technical Writer. Previously, he has worked as Documentation Specialist in the software industry, a Technical Support Specialist in educational industry, and a Technical Journalist in the computer publishing industry.

38 comments
ILUVIT
ILUVIT

In My Computer, I have a drive letter mapped but it does not exist. It was an old network drive map that was at one point disconnected yet Windows still sees it as a mapped drive (Disconnected Network Drive). If I try to unmap it the error given is: The network connection cannot be found. I also cannot map anything to that same letter to overwrite the mapping. Microsoft support (at $300/hr) could not find a solution. Any one here can help? Thx in advance.

jk2001
jk2001

Ahhhhh.... thanks for this good tip. I didn't realize that CMD.EXE doesn't allow you to CD to UNC paths, so you need to map the path to a drive letter first. I'll file this away in "more Windows annoyances."

James Jelinek
James Jelinek

Actually this is a good tip, when you don't want to fuss with having to look/remember what's mapped where, just quick raw access!

timothy.coe.sr
timothy.coe.sr

Thanks for the tip. I too would be interested in the batch file example from Lady Reader. PS I like the tips that are on Tech Republic. What I don't like is those who have negative comments. It is like they are trying to show how superior they are by saying negative things. Ah, but then again maybe we all are not as smart and advanced as them!

pethers
pethers

Didn't you ever learn to use a mouse? ;-P

Realvdude
Realvdude

I wondered about using local paths, so I gave it a try. It did not map a new drive, but did switch to the specified path and POPD returned to the previous path. I executed PUSHD /? to get the help on this command, and it states that it maps a drive only for network paths (UNC?). I also wondered about the PUSH and POP part of the command names, also being stack commands. As expected the command can be nested! So you can push to one path, then push to another path, then pop back along the paths you pushed.

stuart.wood
stuart.wood

Tried this command for the first time having been unaware of it until now - really useful even just for browsing directories quickly - keep's the mouse happy anyway from not having to work so hard! Thanks for the tip!

pmuti
pmuti

Love this command! Some things you just can't do without a drive letter. Also setting prompt=$M$P$G helps when using pushD; gives you that extra bit of information in case you get a little lost on the remote machine.

mhmmd.faisal
mhmmd.faisal

Good Tip. However this also works on Windows 2K3 Servers.

jakesty
jakesty

This is a pretty cool command. I use the command prompt all of the time, don't know why I never ran across this one. The nice thing is that I often temporarily map a drive, and then would normally net use /delete. Now it changes to that drive letter, and a simple POPD to remove. There's not all that much to learn, so I've got it. Very Cool! Thanks, Jake

Open Minded Geek
Open Minded Geek

I agree with David P I'll be sticking with the legacy NET USE command. Just as quick and so much more versatile I wonder ... can Push / Pop D be used in scripts in the same manner that NET USE can?? Food for thought

alessandro.feltrin
alessandro.feltrin

Great and simple ... It does the same that the "net use drive: \\server\share" command does, but it remembers the last used 'drive letter' ... Also popd does the same of the "net use drive: /d" command. Cheers. Alessandro

davidp
davidp

Well this is one command that I won't bother to learn. I will stick to the old fashioned (works with every version since Win95 I think) NET USE. With NET USE I can specify which drive letter to use (so i don't have to go searching to find which letter PUSHD has given me), allows me to specify the credentials of a diferent user (very useful when you as admin want to get to resources that the logged on user doesn't have rights to), and NET USE also lets me disconnect the mapping. PUSHD and POPD may have a place but I would rather extend my knowledge of the NET commands.

HipposRule
HipposRule

Doesn't that exist as well, at least you can specifiy username/password

bgross
bgross

Use the Net Use command to delete a disconnected drive. If the drive you want to remove is Z:, then open a command prompt and type Net Use z: /d

b.gallinger
b.gallinger

Someone mentioned the lack of support for UNC paths at the cmd prompt. By default they are not supported but you can override this by following the steps in this KB http://support.microsoft.com/kb/156276 Though I still think this is a cool tip (pushD).

pmuti
pmuti

"Actually this is a good tip, when you don't want to fuss with having to look/remember what's mapped where, just quick raw access!" I second that! Sometimes you just don't care what drive letters what.. you just need to get what you want and not get involved with picking letters out of hats. Especially when you're moving around to different computers, through rdp/vnc and they all have slightly different mappings. Sometimes it's easier just not knowing. :)

Solenade
Solenade

I'm always writing and running scripts and batch files in an ever-changing environment. I will be using this very helpful command from now on. Thanks for the tip!

etkinsd
etkinsd

for weenies...real software engineers program from the command line.

wiggledbits
wiggledbits

Sure, I know I use it all the time to move from one command prompt session and one SSH session to another all the time. ;-) :-)

Jeff Adams
Jeff Adams

You can use PUSHD on local paths, in a sense, if you have local shares setup or by using administrative shares. C:\>net share Share name Resource Remark ------------------------------------------------------------------------------- IPC$ Remote IPC D$ D:\ Default share C$ C:\ Default share print$ C:\WINDOWS\system32\spool\drivers Printer Drivers I$ I:\ Default share J$ J:\ Default share ADMIN$ C:\WINDOWS Remote Admin C C:\ Caching disabled I_Xfer C:\I Caching disabled SharedDocs C:\DOCUMENTS AND SETTINGS\ALL USERS\DOCUMENTS The command completed successfully. C:\>PushD "\\127.0.0.1\C$\Documents and Settings\Administrator" Z:\Documents and Settings\Administrator>PopD C:\>PushD "\\127.0.0.1\SharedDocs" Z:\>PopD C:\> -Jeff

timboid
timboid

PUSHD and POPD have been around for donkeys years and in my UNIX years, it was one of those bread'n'butter command line actions you just had to use when path names were stupidly long! I think Windows NT was the first to introduce them into the command prompt language, and from my perspective their best use is when you DO need to nest the directory names. But here's another simple drive-mapping command I use occasionally: SUBST (and it's quicker than typing 'NET USE'!!)

eblank
eblank

Nice commmand. While the article implies that this is a command prompt ony thing, the drive mapping nicely shows up in Windows Explorer also. I had Win Explorer ruinning in the background when I issued the command and the Z: drive nicely populated itself and then vanished properly as I issued the PushD and PopD command. Nice toy!

mike.england
mike.england

Perhaps the Open Minded Geek aint so open minded after all. A neat "trick" and very useful

g01d4
g01d4

And not really a way to "temporarily map a drive letter" which 'net use' is for. To perhaps add confusion to some earlier posts, the ntcmds.chm on 'net use' says the /persistent:{yes|no} default "is the setting last used".

Realvdude
Realvdude

Since the command changes you to the new drive mapping. Specifying credentials on the command line are fine, but I hope you don't do that in batch files.

LadyReader
LadyReader

I have a batch job that runs twice daily and executes programs installed in several different folders. I use PushD to redirect to each of the folderpaths and PopD to revert back. I don't reference a drive letter at any time. This job has been running without incident in production for about 3 years.

Realvdude
Realvdude

I remember using SUBST since MSDOS 3.01 on Packard Bell XT computers. One particalur use was for the psuedo workgroup programs we used. Trouble was, unless that workstation was booting from floppy (which was sometimes the case), the "server" couldn't use the same program because of configuration files and embedded drive letters in files. We came up with the solution of SUBSTituting a drive letter that was the same as the shared letter for the rest of the network.

kunze
kunze

Once the pushd has set the drive letter and switched you to the prompt you can enter start . (that is start and a period) and you will be switched to that drive in Windows Explorer. Actually start . works on any drive from the prompt and has nothing to do with pushd.

Photogenic Memory
Photogenic Memory

I was wondering what does your batch script look like? Does the syntax look similar to this exmaple: [snatch,grab, and run with it!] pushd \\workstation1\$g\bkfdocs & copy \\workstation1\$g\bkfdocs c:\localBKF & popd \\workstation1\$g\bkfdocs & exit This is just a made up example. But it should work, right? How did you lay your script out ( minus the ip's and real server names to preserve security). I really would like to know? Thanks in advance.

TheGooch1
TheGooch1

However, I wonder how it( Pushd ) would behave if there are no free drive letters. Does it have an errorlevel that maps to "no available drive letters" ? Otherwise, I think its a great tool, I wonder why I have never heard of it before. Kinda like the "net statistics" command, which I discovered only after about 8 years into my Windows Sysadmin experience.

SysAdminII
SysAdminII

Is there a way to use credentials in PushD like in Net Use? (Ex) I wanted to map a drive to a machine and use a different name and password.

CharlieSpencer
CharlieSpencer

You've provided a use for this that wasn't apparent when I originally read the article. I can make use of this in batch scripts. I'll probably continue to use 'net use' interactively. I'm used to having certain shared resources assigned to the same drive letters every time, and when I switch back and forth my fingers already know what letter to specify :-) Regarding some of the other comments, it's just a tip. If you don't like it, don't use it.

nzimmerman67
nzimmerman67

net use l: \\servername\sharename will only map it for that session. to make permanent, use the -p (persistent) switch

Jim_MacLachlan
Jim_MacLachlan

Net use only keeps the drive mapping after a reboot if you use the /persistent:yes switch. My PC defaults to no - always has. You might be able to change that in the environment variables, but I've never bothered to look into it. Pushd doesn't look particularly useful to me either, but I'll try to keep it in mind. My network is small enough that I keep static mappings to the root of all my server drives anyway. There are times when I need to map a users PC drive, though. I've always used 'net use' - hard not to since it's been the command since the DOS Client days. Old dogs need to learn new tricks, though.

Jeff Adams
Jeff Adams

PUSHD is not designed to pass credentials, but you could use a combination of NET and PUSHD. NET USE \\Server\Share /USER:Domain\Username password && PUSHD \\Server\Share [additional commands] POPD && NET USE \\Server\Share /DELETE The first NET USE authenticates you, giving you access to the share, but does not map the share to a specific drive. PUSHD maps the drive and makes the current working directory the temporary drive (and path, if passed). When you're done with the drive, POPD returns you to your previous location and the second NET USE terminates the connection to the share. -Jeff