How to use createprocess to execute adb program in

2019-09-19 02:38发布

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.

0条回答
登录 后发表回答