{"id":28003,"date":"2007-02-15T10:00:05","date_gmt":"2007-02-15T10:00:05","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2007\/02\/15\/why-cant-you-set-the-command-prompts-current-directory-to-a-unc\/"},"modified":"2007-02-15T10:00:05","modified_gmt":"2007-02-15T10:00:05","slug":"why-cant-you-set-the-command-prompts-current-directory-to-a-unc","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20070215-05\/?p=28003","title":{"rendered":"Why can&#039;t you set the command prompt&#039;s current directory to a UNC?"},"content":{"rendered":"<p>If you try to set the current directory of a command prompt, you get the error message &#8220;CMD does not support UNC paths as current directories.&#8221; What&#8217;s going on here?\n It&#8217;s MS-DOS backwards compatibility.\n If the current directory were a UNC, there wouldn&#8217;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&#8217;t have a drive letter.\n You can work around this behavior by using the <code>pushd<\/code> command to create a temporary drive letter for the UNC. Instead of passing <code>script.cmd<\/code> to the <code>CreateProcess<\/code> function as the <code>lpCommandLine<\/code>, you can pass <code>cmd.exe \/c pushd \\\\server\\share &amp;&amp; script.cmd<\/code>.<\/p>\n<p> (Griping that seems to happen any time I write about batch files, so I&#8217;ll gripe them pre-emptively: Yes, the batch &#8220;language&#8221; sucks because it wasn&#8217;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.) <\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you try to set the current directory of a command prompt, you get the error message &#8220;CMD does not support UNC paths as current directories.&#8221; What&#8217;s going on here? It&#8217;s MS-DOS backwards compatibility. If the current directory were a UNC, there wouldn&#8217;t be anything to return to MS-DOS programs when they call function 19h [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2],"class_list":["post-28003","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>If you try to set the current directory of a command prompt, you get the error message &#8220;CMD does not support UNC paths as current directories.&#8221; What&#8217;s going on here? It&#8217;s MS-DOS backwards compatibility. If the current directory were a UNC, there wouldn&#8217;t be anything to return to MS-DOS programs when they call function 19h [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/28003","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=28003"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/28003\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=28003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=28003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=28003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}