{"id":13543,"date":"2010-07-01T07:00:00","date_gmt":"2010-07-01T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2010\/07\/01\/what-is-the-lpclass-member-of-shellexecuteinfo-used-for\/"},"modified":"2010-07-01T07:00:00","modified_gmt":"2010-07-01T07:00:00","slug":"what-is-the-lpclass-member-of-shellexecuteinfo-used-for","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20100701-00\/?p=13543","title":{"rendered":"What is the lpClass member of SHELLEXECUTEINFO used for?"},"content":{"rendered":"<p>\nA customer reported problems launching\nthe default Web browser with the\n<code>Shell&shy;Execute&shy;Ex<\/code> function:\n<\/p>\n<pre>\nint _tmain(int argc, _TCHAR* argv[])\n{\n  SHELLEXECUTEINFO sei = {0};\n  sei.cbSize = sizeof(sei);\n  sei.nShow = SW_SHOWNORMAL;\n  sei.lpFile = TEXT(\"www.microsoft.com\");\n  sei.fMask = SEE_MASK_CLASSNAME;\n  sei.lpVerb = TEXT(\"opennew\");\n  sei.lpClass = TEXT(\"htmlfile\");\n  ShellExecuteEx(&amp;sei);\n  return 0;\n}\n<\/pre>\n<p>\nThis fails with <code>sei.hInstApp = SE_ERR_FNF<\/code>.\n<\/p>\n<p>\nIf you don&#8217;t pass the <code>SEE_MASK_CLASSNAME<\/code> flag and\nleave <code>lpClass = NULL<\/code>,\nthen the <code>Shell&shy;Execute&shy;Ex<\/code> function will try to\nfigure out what your <code>lpFile<\/code> refers to,\nlooking at the file extension,\nlooking for the file on the <code>PATH<\/code>,\nand if all else fails,\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/01\/13\/512503.aspx\">\ntrying some autocorrection<\/a>.\nIn this case, the customer was relying on the autocorrection,\nsince they left the <code>http:\/\/<\/code> prefix off their URL.\nOne of the default autocorrection rules is that if the item that couldn&#8217;t\nbe launched begins with <code>www<\/code>, then try again with\n<code>http:\/\/<\/code> in front.\n<\/p>\n<p>\nOn the other hand,\nif you pass an explicit <code>lpClass<\/code>,\nthen no name resolution is performed on the <code>lpFile<\/code>.\nYou&#8217;re saying &#8220;Don&#8217;t do any sniffing and poking and autocorrection.\nI have already determined that this item should be executed according\nto the rules specified for\n<code>HKEY_CLASSES_ROOT\\htmlfile<\/code>,\nso just follow the rules and don&#8217;t question me.&#8221;\n<\/p>\n<p>\nNo second-guessing means that the <code>Shell&shy;Execute&shy;Ex<\/code>\nfunction shrugged its shoulders and said,\n&#8220;Well, I don&#8217;t see a file called <code>www.microsoft.com<\/code>\nin the current directory, so I will fail with a file-not-found error.&#8221;\n<\/p>\n<p>\nIf you pass an explicit class, then\n<code>Shell&shy;Execute&shy;Ex<\/code> will\ntreat your <code>lpFile<\/code> as if it were a file of that type.\nIf you have something and you want all the standard detection logic\nto kick in, then don&#8217;t specify a class.\n<\/p>\n<p>\n<b>Bonus reading<\/b>:\nThe above program is simplified to illustrate the topic.\nA real-life version of this program\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2008\/05\/28\/8555658.aspx\">\nneeds some other scaffolding<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer reported problems launching the default Web browser with the Shell&shy;Execute&shy;Ex function: int _tmain(int argc, _TCHAR* argv[]) { SHELLEXECUTEINFO sei = {0}; sei.cbSize = sizeof(sei); sei.nShow = SW_SHOWNORMAL; sei.lpFile = TEXT(&#8220;www.microsoft.com&#8221;); sei.fMask = SEE_MASK_CLASSNAME; sei.lpVerb = TEXT(&#8220;opennew&#8221;); sei.lpClass = TEXT(&#8220;htmlfile&#8221;); ShellExecuteEx(&amp;sei); return 0; } This fails with sei.hInstApp = SE_ERR_FNF. If you don&#8217;t pass [&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":[25],"class_list":["post-13543","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer reported problems launching the default Web browser with the Shell&shy;Execute&shy;Ex function: int _tmain(int argc, _TCHAR* argv[]) { SHELLEXECUTEINFO sei = {0}; sei.cbSize = sizeof(sei); sei.nShow = SW_SHOWNORMAL; sei.lpFile = TEXT(&#8220;www.microsoft.com&#8221;); sei.fMask = SEE_MASK_CLASSNAME; sei.lpVerb = TEXT(&#8220;opennew&#8221;); sei.lpClass = TEXT(&#8220;htmlfile&#8221;); ShellExecuteEx(&amp;sei); return 0; } This fails with sei.hInstApp = SE_ERR_FNF. If you don&#8217;t pass [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/13543","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=13543"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/13543\/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=13543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=13543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=13543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}