Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CreateProcess doesn't pass command line arguments

Hello I have the following code but it isn't working as expected, can't figure out what the problem is.

Basically, I'm executing a process (a .NET process) and passing it command line arguments, it is executed successfully by CreateProcess() but CreateProcess() isn't passing the command line arguments

What am I doing wrong here??

int main(int argc, char* argv[]) {     PROCESS_INFORMATION ProcessInfo; //This is what we get as an [out] parameter      STARTUPINFO StartupInfo; //This is an [in] parameter      ZeroMemory(&StartupInfo, sizeof(StartupInfo));     StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field      LPTSTR cmdArgs = "[email protected]";      if(CreateProcess("D:\\email\\smtp.exe", cmdArgs,          NULL,NULL,FALSE,0,NULL,         NULL,&StartupInfo,&ProcessInfo))     {          WaitForSingleObject(ProcessInfo.hProcess,INFINITE);         CloseHandle(ProcessInfo.hThread);         CloseHandle(ProcessInfo.hProcess);          printf("Yohoo!");     }       else     {         printf("The process could not be started...");     }      return 0; } 

EDIT: Hey one more thing, if I pass my cmdArgs like this:

// a space as the first character LPTSTR cmdArgs = " [email protected]"; 

Then I get the error, then CreateProcess returns TRUE but my target process isn't executed.

Object reference not set to an instance of an object 
like image 666
akif Avatar asked Jul 16 '09 06:07

akif


1 Answers

You should specify also the module name in parameters: LPTSTR cmdArgs = "App [email protected]"; It should be the whole command line (including argv[0]).

like image 142
EFraim Avatar answered Sep 23 '22 09:09

EFraim