开发者

CreateProcess don't work on all applications

I am writing a little GUI application that is used to start other external executables. It works on all the executables I want, except one. Here is the code I'm using:

CreateProcess(FullPathOfExternalApp.c_str(), NULL, NULL, NULL, false, CREATE_DEFAULT_ERROR_MODE, 0, 0, &siStartupInfo, &piProcessInfo)

Is it possible that the exte开发者_如何学Crnal app has a built-in mechanism that prevents it from being executed by another executable?

Thank you very much


I would start by getting the last system error and then formatting it and dumping it out, something along the lines of:

std::string getSystemErrorMsg()
{
    LPVOID lpMsgBuf;
    ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL );

    std::string err = reinterpret_cast<const char *>( lpMsgBuf );

    ::LocalFree( lpMsgBuf );

    return err;
}

I would call a function like that right after CreateProcess fails and then pass the err string to OutputDebugString() and use something like DebugView to monitor the output. Sometimes the OS can let you know why it won't do something you expect it to do, not always, but I would at least start there.


There's nothing special in using CreateProcess() to start a program. Your problem is elsewhere. It might be a 64-bit executable on a 32-bit system (won't run), it can be missing dependencies, it can be something else related to the environment. Your best bet is to use Process Monitor utility to check the most likely reasons.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜