{"id":93131,"date":"2016-03-09T07:00:00","date_gmt":"2016-03-09T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=93131"},"modified":"2019-03-13T10:31:20","modified_gmt":"2019-03-13T17:31:20","slug":"20160309-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20160309-00\/?p=93131","title":{"rendered":"String comparisons against program output is not usually the best solution"},"content":{"rendered":"<p>A customer wanted to know whether the <code>ICACLS<\/code> program will be deprecated in Windows 10. <\/p>\n<p>The reason is that they have a program that modifies file and directory permission, and the way it works is that the program runs the <code>ICACLS<\/code> program, then parses the output to see whether it succeeded. They are working on a new release and wanted to know what APIs they should be using, and whether their existing technique was still going to work. <\/p>\n<p>As a general rule, programs are designed for human consumption, not programmatic consumption. (There are exceptions, like <code>sort<\/code>, or reporting tools that are designed to have their output parsed.) But if you&#8217;re going to be tied to the exact number of spaces between the date and the file size, or the user&#8217;s date and number formatting settings, or the letters A-c-c-e-s-s and d-e-n-i-e-d. then you&#8217;re going to run into trouble. <\/p>\n<p>If you&#8217;re going to be manipulating file security, then you should be using functions like <code>Set&shy;Named&shy;Security&shy;Info<\/code>, which are part of the formal and documented API surface of Windows. <\/p>\n<p>I found this question surprising because it came from a German customer, so they were presumably doing string comparisons against &#8220;<span LANG=\"de\">Zugriff verweigert<\/span>&#8220;, and all their customers were in German-speaking countries. Either that, or they told their customers to install the English version of Windows. <\/p>\n<p><b>Bonus chatter<\/b>: One of my colleagues recommends <a HREF=\"http:\/\/www.amazon.com\/Programming-Windows-Security-Keith-Brown\/dp\/0201604426?tag=tholneth-20\"><i>Programming Windows Security<\/i><\/a> for those who want to understand more on the topic. Just passing along the recommendation; I haven&#8217;t read the book myself. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Look for programmatic interfaces.<\/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":[25],"class_list":["post-93131","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Look for programmatic interfaces.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/93131","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=93131"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/93131\/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=93131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=93131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=93131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}