Search code examples
winapilaunching-application

Launch exe/shortcut and not care about return


I was trying to launch exe files and shortcuts that point to exe files (shortcuts may have command line arguments on them). I was looking for a winapi way to launch them such that the return value is not cared/waited for. I have only found ways where it either blocks till the launched file exits, or asynchronously waits till it exits. Is there a way that just triggers it to launch and doesn't care beyond that? Basically like the user double click that exe/shortcut.


Solution

  • Easy using ShellExecuteEx:

    SHELLEXECUTEINFO sei = {0};
    sei.cbSize = sizeof(sei);
    sei.lpFile = L"c:\\path\\to\\your\\shortcut.lnk";
    sei.nShow = SW_SHOWNORMAL;
    ShellExecuteEx(&sei);