Using CreateProcess to invoke an exe file?

泪湿孤枕 提交于 2019-12-06 00:22:45

Ok, so cracked it finally after trying out a lot of flags from the documentation. Hope it's helpful for anyone else struggling with it.

#include<Windows.h>

int main()
{
    STARTUPINFO si = { sizeof(STARTUPINFO) };
    si.cb = sizeof(si);
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_HIDE;
    PROCESS_INFORMATION pi;
    CreateProcess("C:\\Program Files\\Nero\\Nero 7\\Core\\nero.exe", NULL , NULL, NULL, FALSE, CREATE_NO_WINDOW , NULL, NULL, &si, &pi);
}//main

Note that Nero's GUI will show up, but some other exe's which you may try will start, but the window won't be visible. You'll be able to see the application in TaskManager though.

The most likely cause is your STARTUPINFO struct. At a minimum, you need to set the cb member to sizeof(STARTUPINFO). Here's how I like to do it:

STARTUPINFO si = {sizeof(STARTUPINFO)};

Also, you're not checking the results of CreatePipe for failure.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!