{"id":91331,"date":"2015-10-19T07:00:00","date_gmt":"2015-10-19T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20151019-00\/?p=91331\/"},"modified":"2019-03-13T12:20:43","modified_gmt":"2019-03-13T19:20:43","slug":"20151019-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20151019-00\/?p=91331","title":{"rendered":"How do I get the user-customized name of a mapped network drive?"},"content":{"rendered":"<p><a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2015\/10\/12\/10647157.aspx\">Last time<\/a>, we displayed the names of This PC and Recycle Bin. This time, we&#8217;ll look at mapped volumes, because they are a little tricky. <\/p>\n<p>When you map a network drive, the name in Explorer defaults to something like <i>sharename (\\\\server) (Z:)<\/i>. But you can right-click the label, select Rename, and change it to <i>Awesome<\/i> if you like. <\/p>\n<p>Let&#8217;s try to retrieve the name <i>Awesome<\/i>. Take the program from last time and make these changes: <\/p>\n<pre>\nint __cdecl wmain(int argc, wchar_t **argv)\n{\n  CoInitialize(0);\n  <font COLOR=\"blue\">IShellItem* item;\n  SHCreateItemFromParsingName(argv[1], nullptr,\n                              IID_PPV_ARGS(&amp;item));\n  PrintDisplayName(item, SIGDN_NORMALDISPLAY, L\"name\");\n  item-&gt;Release();<\/font>\n  CoUninitialize();\n  return 0;\n}\n<\/pre>\n<p>This prints the display name of whatever you pass on the command line. Let&#8217;s say that drive Z: is mapped to <code>\\\\server\\sharename<\/code>. <\/p>\n<p>Run the program with the command line parameter <code>Z:<\/code>, <\/p>\n<pre>\nname = sharename (\\\\server) (Z:)\n<\/pre>\n<p>Now go to Explorer and rename the drive to <i>Awesome<\/i>. Then run the program again with <code>Z:<\/code> on the command line. <\/p>\n<pre>\nname = Awesome (Z:)\n<\/pre>\n<p>Close. We got the <i>Awesome<\/i> part, but the non-awesome drive letter is still there. That sort of makes sense, since Explorer also shows the non-awesome drive letter. <\/p>\n<p>But what if you really want it without the drive letter? Well, you can ask for a different kind of display name. <\/p>\n<pre>\nint __cdecl wmain(int argc, wchar_t **argv)\n{\n  CoInitialize(0);\n  IShellItem* item;\n  SHCreateItemFromParsingName(argv[1], nullptr,\n                              IID_PPV_ARGS(&amp;item));\n  PrintDisplayName(item, <font COLOR=\"blue\">SIGDN_PARENTRELATIVEEDITING<\/font>, L\"name\");\n  item-&gt;Release();\n  CoUninitialize();\n  return 0;\n}\n<\/pre>\n<p>This time, we ask for the parent-relative editing name. This is the name used by the Rename command when you rename an item that is displayed relative to its parent. <\/p>\n<p>Run the program with <code>Z:<\/code> on the command line, and see what happens: <\/p>\n<pre>\nname = Awesome\n<\/pre>\n<p>Awesome. <\/p>\n<p>For those who want to do things the classic way, you can use the <code>SHGDN_IN&shy;FOLDER | SHGDN_FOR&shy;EDITING<\/code> flags. <\/p>\n<p>Take the second program (the one that uses the classic style) and make these changes: <\/p>\n<pre>\nint __cdecl wmain(int argc, wchar_t **argv)\n{\n  CoInitialize(0);\n  <font COLOR=\"blue\">PIDLIST_ABSOLUTE absolute;\n  SHParseDisplayName(argv[1], nullptr, &amp;absolute, 0, nullptr);\n  PrintDisplayName(absolute, SHGDN_INFOLDER | SHGDN_FOREDITING, L\"name\");\n  CoTaskMemFree(absolute);<\/font>\n  CoUninitialize();\n  return 0;\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Ask the shell. That is, after all, how the shell displays is.<\/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-91331","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Ask the shell. That is, after all, how the shell displays is.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/91331","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=91331"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/91331\/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=91331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=91331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=91331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}