{"id":24433,"date":"2007-11-21T10:00:00","date_gmt":"2007-11-21T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2007\/11\/21\/hidden-gotcha-the-command-processors-autorun-setting\/"},"modified":"2007-11-21T10:00:00","modified_gmt":"2007-11-21T10:00:00","slug":"hidden-gotcha-the-command-processors-autorun-setting","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20071121-00\/?p=24433","title":{"rendered":"Hidden gotcha: The command processor&#039;s AutoRun setting"},"content":{"rendered":"<p>\nIf you type <code>cmd \/?<\/code> at a command prompt, the command\nprocessor will spit out pages upon pages of strange geeky text.\nI&#8217;m not sure why the command processor folks decided to write\ndocumentation this way rather than the more traditional manner\nof putting it into MSDN or the online help.\nMaybe because that way they don&#8217;t have to deal with annoying\npeople like &#8220;editors&#8221; telling them\nthat their documentation contains grammatical errors or\nis hard to understand.\n<\/p>\n<p>\nAnyway, buried deep in the text is this little gem:\n<\/p>\n<pre>\nIf \/D was NOT specified on the command line, then when CMD.EXE starts, it\nlooks for the following REG_SZ\/REG_EXPAND_SZ registry variables, and if\neither or both are present, they are executed first.\n    HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Command Processor\\AutoRun\n        and\/or\n    HKEY_CURRENT_USER\\Software\\Microsoft\\Command Processor\\AutoRun\n<\/pre>\n<p>\nI sure hope there is some legitimate use for this setting,\nbecause the only time I see anybody mention it is when it\ncaused them massive grief.\n<\/p>\n<blockquote CLASS=\"q\">\n<p>\nI must be losing my mind, but I can&#8217;t even write a stupid <code>for<\/code>\ncommand to parse the output of a command.\n<\/p>\n<pre>\nC:\\test&gt;for \/f \"usebackq delims=\" %i in (`dir \/ahd\/b`) do @echo %i\n<\/pre>\n<p>\nWhen I run this command, I get\n<\/p>\n<pre>\nRECYCLER\nSystem Volume Information\nWUTemp\n<\/pre>\n<p>\nYet when I type the command manually, I get completely different\noutput!\n<\/p>\n<pre>\nC:\\test&gt;dir \/ahd\/b\ntest_hidden\n<\/pre>\n<p>\nHave I gone completely bonkers?\n<\/p>\n<\/blockquote>\n<p>\nThe original problem was actually much more bizarro because\nthe command whose output the customer was trying to parse merely\nprinted a strange error message,\nyet running the command manually generated the expected output.\n<\/p>\n<p>\nAfter an hour and a half of head-scratching, somebody suggested\ntaking a look at the command processor&#8217;s <code>AutoRun<\/code>\nsetting, and lo and behold, it was set!\n<\/p>\n<pre>\nC:\\test&gt;reg query \"HKCU\\Software\\Microsoft\\Command Processor\" \/v AutoRun\n! REG.EXE VERSION 3.0\nHKEY_CURRENT_USER\\Software\\Microsoft\\Command Processor\n    <font COLOR=\"blue\">AutoRun     REG_SZ  cd\\<\/font>\n<\/pre>\n<p>\nThe customer had no idea how that setting got there,\nbut it explained everything.\nWhen the command processor ran the <code>dir \/ahd\/b<\/code> command\nas a child process (in order to parse its output),\nit first ran the <code>AutoRun<\/code> command,\nwhich changed the current directory to the drive&#8217;s root.\nAs a result, the <code>dir \/ahd\/b<\/code>\nproduced a listing of the hidden subdirectories of the root directory\nrather than the hidden subdirectories of the <code>C:\\test<\/code> directory.\n<\/p>\n<p>\nIn the original formulation of the problem, the command the customer\nwas trying to run looked for its configuration files in the current\ndirectory, and the <code>cd\\<\/code> in the <code>AutoRun<\/code>\nmeant that the program looked for its configuration files in the\nroot directory instead of the <code>C:\\test<\/code>\ndirectory.\nThus came the error message (&#8220;Configuration file not found&#8221;)\nand the plea for help that\nwas titled, &#8220;Why can&#8217;t the XYZ command find a configuration file\nthat&#8217;s right there in front of it?&#8221;\n<\/p>\n<p>\nLike I said, I&#8217;m sure there must be some valid reason for the\n<code>AutoRun<\/code> setting,\nbut I haven&#8217;t yet found one.\nAll I&#8217;ve seen is the havoc it plays.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you type cmd \/? at a command prompt, the command processor will spit out pages upon pages of strange geeky text. I&#8217;m not sure why the command processor folks decided to write documentation this way rather than the more traditional manner of putting it into MSDN or the online help. Maybe because that way [&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":[104],"class_list":["post-24433","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-tipssupport"],"acf":[],"blog_post_summary":"<p>If you type cmd \/? at a command prompt, the command processor will spit out pages upon pages of strange geeky text. I&#8217;m not sure why the command processor folks decided to write documentation this way rather than the more traditional manner of putting it into MSDN or the online help. Maybe because that way [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/24433","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=24433"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/24433\/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=24433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=24433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=24433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}