title: Use CreateProcess to execute ADB command
body: <p>I want to use CreateProcess() to execute an ADB command that launches an application/activity. It works using the simpler system(command) function, but I want to eliminate the creation of the command line window by system(). Below is what I have right now. I have tried using different CreateProcess()es, like CreateProcessW and CreateProcessA, but to no avail.</p>
  
  <pre><code>char prog[] = "C:\\Program Files\\Android\\sdk\\platform-tools\\platform-tools\\adb.exe";
  char args[] = "adb shell am start -a android.intent.action.MAIN -n com.example.dmiller.myapplication/.Blankscreen";
  
  STARTUPINFO si;
  PROCESS_INFORMATION pi;
  
  ZeroMemory(&amp;si, sizeof(si));
  si.cb = sizeof(si);
  ZeroMemory(&amp;pi, sizeof(pi));
  
  CreateProcess((LPCWSTR)prog, (LPWSTR)args, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &amp;si, &amp;pi);
  </code></pre>
  
  <p>I got this partially from this answer <a href="https://stackoverflow.com/questions/27883824/how-to-use-createprocess-to-execute-adb-program-in-path">How to use createprocess to execute adb program in PATH?</a> but when the command should be executed in my program, nothing happens (when running system(cmd.c_str()), the appropriate app is launched on the attached device). Could anyone provide some help? Alternative methods are welcome as well.</p>
  
  <p>UPDATE: I have applied some things from the below post to try to provide a better question. Code has been updated to my latest version.</p>
  
  <p><a href="https://stackoverflow.com/questions/1135784/createprocess-doesnt-pass-command-line-arguments?rq=1">CreateProcess doesn&#39;t pass command line arguments</a></p>