CreateProcessW does not execute command line

I am trying to implement CreateProcessW in a DLL so that the user can run the application in a separate process.

For starters, I hardcode the commands in the code until I figure it out.

I have

STARTUPINFO si = {sizeof(STARTUPINFO), 0};
si.cb = sizeof(si);
PROCESS_INFORMATION pi = {0};
LPCTSTR AppName=L"c:\\utilities\\depends.exe";
LPTSTR Command = L"c:\\utilities\\tee.exe";
if (CreateProcessW(AppName, Command, 0, 0, 0, CREATE_DEFAULT_ERROR_MODE, 0, 0, &si, &pi)) {
        CloseHandle(pi.hThread);
        CloseHandle(pi.hProcess);
        return GX_RESULT_OK;
    } else {
        .. show error msg
    }

This will launch Depends, but will not open Tee.exe. There is no error, it just ignores the command line option. The parameters are correct, and I can run it on the command line, and it works fine. If you leave AppName empty and specify Depends.exe as the Command parameter, it also works, but if I specify

LPTSTR Command = L"c:\\utilities\\depends.exe c:\\utilities\\tee.exe";

I get Error 3: "The system cannot find the path specified."

Also, by specifying the lpCurrentDirectory parameter, it is also ignored.

+4
source share
1

command

  • Appname
  • command argv[0]

t.txt , :

  • Appname = "c:/windows/notepad.exe";
  • command = "notepad c:/temp/t.txt";

, , .

: command = "fake c:/temp/t.txt";

notepad.exe:

  • argv[0] = "notepad";
  • argv[1] = "c:/temp/t.txt";

:

#include <Windows.h>
#include <iostream>

using namespace std;

int main(){
    STARTUPINFO si = {sizeof(STARTUPINFO), 0};
    si.cb = sizeof(si);
    PROCESS_INFORMATION pi = {0};
    LPTSTR AppName=L"C:/Windows/notepad.exe";
    wchar_t Command[] = L"notepad C:/Temp/t.txt"; 
    DWORD res = CreateProcess(AppName, Command, 0, 0, 0, CREATE_DEFAULT_ERROR_MODE, 0, 0, &si, &pi);
    if (res) {
        CloseHandle(pi.hThread);
        CloseHandle(pi.hProcess);
        return 0;
    } else {
        cerr<<"error..."<<GetLastError()<<endl;
    }; 
    return 0;
}
+1

All Articles