{"id":1823,"date":"2014-02-10T07:00:00","date_gmt":"2014-02-10T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/02\/10\/execute-a-file-as-if-it-were-a-program-even-though-its-extension-is-not-exe\/"},"modified":"2014-02-10T07:00:00","modified_gmt":"2014-02-10T07:00:00","slug":"execute-a-file-as-if-it-were-a-program-even-though-its-extension-is-not-exe","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20140210-00\/?p=1823","title":{"rendered":"Execute a file as if it were a program, even though its extension is not EXE"},"content":{"rendered":"<p>\nToday&#8217;s Little Program executes a file as if it were a program,\neven though its extension is not EXE.\nThe idea here is to prevent somebody from running your program\nby accident, so you give it an extension like <code>.MOD<\/code>.\nThis is great for preventing somebody from running the program\nby mistake, but how do you do it on purpose?\n<\/p>\n<pre>\n#define STRICT\n#include &lt;windows.h&gt;\n#include &lt;shellapi.h&gt;\nint WINAPI WinMain(\n    HINSTANCE hinst, HINSTANCE hinstPrev,\n    LPSTR lpCmdLine, int nCmdShow)\n{\n  SHELLEXECUTEINFO sei = { 0 };\n  sei.cbSize = sizeof(sei);\n  sei.nShow = SW_SHOWNORMAL;\n  sei.lpFile = TEXT(\"C:\\\\full\\\\path\\\\to\\\\program.mod\");\n  sei.fMask = SEE_MASK_CLASSNAME;\n  sei.lpVerb = TEXT(\"open\");\n  sei.lpClass = TEXT(\"exefile\");\n  ShellExecuteEx(&amp;sei);\n  return 0;\n}\n<\/pre>\n<p>\nWe&#8217;re merely\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/07\/01\/10033224.aspx\">\nusing the <code>lpClass<\/code> member of the\n<code>SHELL&shy;EXECUTE&shy;INFO<\/code> structure<\/code><\/a>\nto force the file to be interpreted as the type we specify,\noverriding the default type inference code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s Little Program executes a file as if it were a program, even though its extension is not EXE. The idea here is to prevent somebody from running your program by accident, so you give it an extension like .MOD. This is great for preventing somebody from running the program by mistake, but how do [&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-1823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Today&#8217;s Little Program executes a file as if it were a program, even though its extension is not EXE. The idea here is to prevent somebody from running your program by accident, so you give it an extension like .MOD. This is great for preventing somebody from running the program by mistake, but how do [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/1823","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=1823"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/1823\/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=1823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=1823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=1823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}