{"id":26863,"date":"2007-05-15T10:00:00","date_gmt":"2007-05-15T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2007\/05\/15\/command-lines-need-to-be-quoted-paths-dont\/"},"modified":"2007-05-15T10:00:00","modified_gmt":"2007-05-15T10:00:00","slug":"command-lines-need-to-be-quoted-paths-dont","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20070515-00\/?p=26863","title":{"rendered":"Command lines need to be quoted; paths don&#039;t"},"content":{"rendered":"<p>While it&#8217;s true that one category of problems comes from <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2003\/08\/27\/54715.aspx\"> failing to quote spaces in command lines<\/a>, it is a false statement that &#8220;<a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/pages\/407234.aspx#429980\">path names in the registry should have quotation marks around them for obvious reasons<\/a>.&#8221; In fact it&#8217;s the opposite. Path names should <i>not<\/i> be quoted.\n Think about it: Quotation marks are a parsing issue, not a file name issue. The quotation marks are not part of the file name. If you type <code>dir<\/code> or open the folder in Explorer, you don&#8217;t see any quotation marks. You can&#8217;t pass quotation marks to <code>CreateFile<\/code> or <code>GetFileAttributes<\/code> since they aren&#8217;t actually part of the file name.\n Quotation marks indicate to code that is parsing a command line that a space should not be interpreted as the end of the command line token. Therefore, you need quotation marks when the string will be interpreted as a command line, such as in the <code>lpCommandLine<\/code> parameter to <code>CreateProcess<\/code> (but not the <code>lpApplicationName<\/code> parameter). Many places in the registry allow you to specify a command line, such as in the <code>Run<\/code> key or in the <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/shellcc\/platform\/shell\/programmersguide\/shell_basics\/shell_basics_extending\/fileassociations\/fa_verbs.asp\"> registration of static verbs<\/a>. If the string will be used as a command line, then you need to quote the spaces so that the command line parser knows where the program name ends and the command line arguments begin.\n In the example in the linked comment, the registry key in question is a list of paths to files, not a list of command lines. Since it&#8217;s not a command line, quotation marks would result in an invalid file name, since quotation marks are not legal file name characters.\n The correct statement of the rule is that <i>command lines<\/i> in the registry should have quotation marks to protect spaces. Path names, on the other hand, not only do not require quotation marks, but in fact <i>must not<\/i> have quotation marks, because the quotation mark is not a part of the file name.\n <b>Nitpicker&#8217;s corner<\/b><\/p>\n<p> Observe that at no point did I claim that Microsoft employees are perfect. <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2007\/05\/04\/2402028.aspx\"> Microsoft employees make mistakes, too<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>While it&#8217;s true that one category of problems comes from failing to quote spaces in command lines, it is a false statement that &#8220;path names in the registry should have quotation marks around them for obvious reasons.&#8221; In fact it&#8217;s the opposite. Path names should not be quoted. Think about it: Quotation marks are a [&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":[26],"class_list":["post-26863","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>While it&#8217;s true that one category of problems comes from failing to quote spaces in command lines, it is a false statement that &#8220;path names in the registry should have quotation marks around them for obvious reasons.&#8221; In fact it&#8217;s the opposite. Path names should not be quoted. Think about it: Quotation marks are a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/26863","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=26863"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/26863\/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=26863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=26863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=26863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}