News, Product Information, and Tips
Check out our free utlities in the downloads section

Simplify UNC usage in command line batch files

by Steve Wiseman on February 19, 2007 · 4 comments

in Windows

Many times a UNC path does not work properly in a command line bat file. This is a hold over from DOS, a compromise to ensure backward compatibility.

Command Line UNC

I have found a little known command (At least to me). Actually there are two of them.

PUSHD, and POPD

Call PUSHD with a UNC share as a single argument and it automatically maps the UNC share to a drive letter. (It starts at Z: and moves backward). So, if we wanted to run a few command line programs within our share we would call it like this:

pushd \\server\share
command1.exe
command2.exe

Command Line UNC PUSHD

When you are finished, and want to remove the mapping you call popd. Putting it all together we have this:

pushd \\server\share
command1.exe
command2.exe
popd

Command Line UNC POPD

I have tested this with Windows NT 4 SP6, and it works all the way through Vista…so you are safe using it on any of these versions of Windows.

Like this article? Then sign up for my newsletter to get free tips and software sent right to your inbox once a week. Like you, I hate spam – I will never spam, or sell your email address.

Related Articles:

{ 4 comments… read them below or add one }

1 Nihal March 1, 2010 at 3:53 am

Thanks! This worked perfectly when using batch files in XP Mode from within Windows 7 (I had to use it to run Fortran, long story :) )

2 Ciprian Cornea June 22, 2010 at 11:15 am

Thanks Steve!

It did the job also for me too.
Now, the Windows Task Scheduler is able to run my batch job to copy files from a network drive to a Sharepoint share.

Ciprian.

3 Zim June 29, 2010 at 10:25 pm

Won’t map a drive for UNC paths deeper than 2 folders.
Why?

4 ashit kamani July 1, 2010 at 11:14 am

Hii, thanx a lot
dis worked perfectly for me in my project.

Leave a Comment

t