How to use createprocess to execute adb program in PATH?

牧云@^-^@ 提交于 2019-12-25 14:04:45

问题


I have add the adb location into PATH. In my C project, I want to execute the flowing cmd:

char *broadcastStop = "adb shell am broadcast -a NotifyServiceStop";

char *forward = "adb forward tcp:12582 tcp:10086";

char *broadcastStart = "adb shell am broadcast -a NotifyServiceStart";

I can run the above using system() well. Now I want to run those hiding the console. I have found many similar question, and told CreateProcess can do.

Here is my code:

void system_hide(char *cmd)
{
    STARTUPINFOW si;
    PROCESS_INFORMATION pi;

    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    ZeroMemory(&pi, sizeof(pi));

    if (CreateProcessW(NULL, cmd, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
    {
    WaitForSingleObject(pi.hProcess, INFINITE);
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);

    }
}

It doesn't run correctly,

I guess that the params to CreateProcess is wrong.

Hope for a correct version. Thanks in advance.

来源:https://stackoverflow.com/questions/27883824/how-to-use-createprocess-to-execute-adb-program-in-path

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