Why can't you set the command prompt's current directory to a UNC?

Raymond Chen

If you try to set the current directory of a command prompt, you get the error message “CMD does not support UNC paths as current directories.” What’s going on here? It’s MS-DOS backwards compatibility. If the current directory were a UNC, there wouldn’t be anything to return to MS-DOS programs when they call function 19h (Get current drive). That function has no way to return an error code, so you have to return a drive letter. UNCs don’t have a drive letter. You can work around this behavior by using the pushd command to create a temporary drive letter for the UNC. Instead of passing script.cmd to the CreateProcess function as the lpCommandLine, you can pass cmd.exe /c pushd \\server\share && script.cmd.

(Griping that seems to happen any time I write about batch files, so I’ll gripe them pre-emptively: Yes, the batch “language” sucks because it wasn’t designed; it just evolved. I write this not because I expect you to enjoy writing batch files but because you might find yourself forced to deal with them. If you would rather abandon batch files and use a different command interpreter altogether, then more power to you.)

0 comments

Discussion is closed.

Feedback usabilla icon