{"id":37193,"date":"2004-11-26T07:00:00","date_gmt":"2004-11-26T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/11\/26\/simple-things-you-can-do-with-the-shellexecuteex-function\/"},"modified":"2004-11-26T07:00:00","modified_gmt":"2004-11-26T07:00:00","slug":"simple-things-you-can-do-with-the-shellexecuteex-function","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20041126-00\/?p=37193","title":{"rendered":"Simple things you can do with the ShellExecuteEx function"},"content":{"rendered":"<p><P>\nHere&#8217;s a tiny little program:\n<\/P>\n<PRE>\n#include &lt;windows.h&gt;\n#include &lt;shellapi.h&gt;<\/p>\n<p>int __cdecl main(int argc, char **argv)\n{\n  if (argc == 3) {\n    SHELLEXECUTEINFO sei = { sizeof(sei) };\n    sei.fMask = SEE_MASK_FLAG_DDEWAIT;\n    sei.nShow = SW_SHOWNORMAL; \/\/ added 27 Nov\n    sei.lpVerb = argv[1];\n    sei.lpFile = argv[2];\n    ShellExecuteEx(&amp;sei);\n  }\n  return 0;\n}\n<\/PRE>\n<P>\nThis is a little program that takes two parameters,\nthe first being the verb and the second the file upon which\nto execute the verb.  Notice that since we exit immediately,\nwe need to set the <CODE>SEE_MASK_FLAG_DDEWAIT<\/CODE> flag:\nNormally, the ShellExecuteEx function assumes that there will\nbe a message pump running after it returns.\nThis allows it to return quickly and continue any necessary\nDDE conversations as the responses arrive from the DDE server.\nBut if the thread is exiting or if the thread is not a GUI thread\n(both of which are true here), you want to suppress this behavior\nbecause there is no message pump around to complete the DDE\nconversation.  Setting the <CODE>SEE_MASK_FLAG_DDEWAIT<\/CODE> flag\nindicates that the ShellExecuteEx function should finish its\nDDE conversation before it returns.\n<\/P>\n<P>\nAnyway, I wrote this little program to illustrate two of the\n<A HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/shellcc\/platform\/shell\/programmersguide\/shell_basics\/shell_basics_extending\/context.asp\">\ncanonical verbs<\/A> that you can use.\nIt seems the people don&#8217;t realize that ShellExecuteEx can be\nused to perform these actions, since it gets asked a lot&#8230;\n<\/P>\n<UL>\n<LI><CODE>shex find %windir%<\/CODE><BR>\n    Opens the search window with a specified folder as the\n    default &#8220;Search in&#8221; location.\n<LI><CODE>shex openas C:\\AUTOEXEC.BAT<\/CODE><BR>\n    Displays the &#8220;Open with&#8221; dialog for a file.\n<\/UL><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a tiny little program: #include &lt;windows.h&gt; #include &lt;shellapi.h&gt; int __cdecl main(int argc, char **argv) { if (argc == 3) { SHELLEXECUTEINFO sei = { sizeof(sei) }; sei.fMask = SEE_MASK_FLAG_DDEWAIT; sei.nShow = SW_SHOWNORMAL; \/\/ added 27 Nov sei.lpVerb = argv[1]; sei.lpFile = argv[2]; ShellExecuteEx(&amp;sei); } return 0; } This is a little program that takes [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-37193","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Here&#8217;s a tiny little program: #include &lt;windows.h&gt; #include &lt;shellapi.h&gt; int __cdecl main(int argc, char **argv) { if (argc == 3) { SHELLEXECUTEINFO sei = { sizeof(sei) }; sei.fMask = SEE_MASK_FLAG_DDEWAIT; sei.nShow = SW_SHOWNORMAL; \/\/ added 27 Nov sei.lpVerb = argv[1]; sei.lpFile = argv[2]; ShellExecuteEx(&amp;sei); } return 0; } This is a little program that takes [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/37193","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=37193"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/37193\/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=37193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=37193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=37193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}