Open an executable file without an “.exe” extension with ShellExecute

前端 未结 1 1459
傲寒
傲寒 2021-01-06 13:21

I want to open an executable file that have no \".exe\" extension with ShellExecute. I can use CreateProcess but I prefer to use ShellExecute. There is any way to do it?

1条回答
  •  醉梦人生
    2021-01-06 13:34

    You use the lpClass member of the SHELLEXECUTEINFO structure to say, "I want you to treat this file as if it were an EXE, even though it doesn't look like one from the extension."

    int _tmain(int argc, _TCHAR* argv[])
    {
      SHELLEXECUTEINFO sei = {0};
      sei.cbSize = sizeof(sei);
      sei.nShow = SW_SHOWNORMAL;
      sei.lpFile = TEXT("myprogram.wrongextension");
      sei.fMask = SEE_MASK_CLASSNAME;
      sei.lpVerb = TEXT("open");
      sei.lpClass = TEXT("exefile");
      ShellExecuteEx(&sei);
      return 0;
    }
    

    0 讨论(0)
提交回复
热议问题