CreateProcess doesn’t passes command line arguments [modified]
-
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] parameterSTARTUPINFO StartupInfo; //This is an \[in\] parameter ZeroMemory(&StartupInfo, sizeof(StartupInfo)); StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field LPTSTR cmdArgs = "name@example.com"; 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;
}
Hey one more thing, if I pass my cmdArgs like this:
// a space as the first character
LPTSTR cmdArgs = " manzoor10@gmail.com";I get the error:
Object reference not set to an instance of an object
then CreateProcess returns TRUE but my target process isn't executed.
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.
modified on Thursday, June 10, 2010 2:13 AM
-
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] parameterSTARTUPINFO StartupInfo; //This is an \[in\] parameter ZeroMemory(&StartupInfo, sizeof(StartupInfo)); StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field LPTSTR cmdArgs = "name@example.com"; 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;
}
Hey one more thing, if I pass my cmdArgs like this:
// a space as the first character
LPTSTR cmdArgs = " manzoor10@gmail.com";I get the error:
Object reference not set to an instance of an object
then CreateProcess returns TRUE but my target process isn't executed.
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.
modified on Thursday, June 10, 2010 2:13 AM
good morning Not sure it will solve your problem but did you notice that lpCommandLine is an in out parameter ? in MSDN Help i found the following information: The Unicode version of this function, CreateProcessW, can modify the contents of this string. Therefore, this parameter cannot be a pointer to read-only memory (such as a const variable or a literal string). If this parameter is a constant string, the function may cause an access violation. Hope this will help. Regards Franck
-
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] parameterSTARTUPINFO StartupInfo; //This is an \[in\] parameter ZeroMemory(&StartupInfo, sizeof(StartupInfo)); StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field LPTSTR cmdArgs = "name@example.com"; 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;
}
Hey one more thing, if I pass my cmdArgs like this:
// a space as the first character
LPTSTR cmdArgs = " manzoor10@gmail.com";I get the error:
Object reference not set to an instance of an object
then CreateProcess returns TRUE but my target process isn't executed.
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.
modified on Thursday, June 10, 2010 2:13 AM
This: http://bobmoore.mvps.org/Win32/w32tip46.htm[^] may give you some insight but I'm not sure. I always use CreateProcess by concatenating the app name and the arguments and set this as the second parameter (first parameter set to NULL) and it has never failed.
-
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] parameterSTARTUPINFO StartupInfo; //This is an \[in\] parameter ZeroMemory(&StartupInfo, sizeof(StartupInfo)); StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field LPTSTR cmdArgs = "name@example.com"; 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;
}
Hey one more thing, if I pass my cmdArgs like this:
// a space as the first character
LPTSTR cmdArgs = " manzoor10@gmail.com";I get the error:
Object reference not set to an instance of an object
then CreateProcess returns TRUE but my target process isn't executed.
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.
modified on Thursday, June 10, 2010 2:13 AM
I suspect your command-line argument is being interpreted as the executable name. See the CreateProcess[^] documentation:
Console processes written in C can use the argc and argv arguments to parse the command line. Because argv[0] is the module name, C programmers generally repeat the module name as the first token in the command line.
While that's talking about C programs, .NET programs conform to that as well. Add an argument before the e-mail address and you should find it all works.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
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] parameterSTARTUPINFO StartupInfo; //This is an \[in\] parameter ZeroMemory(&StartupInfo, sizeof(StartupInfo)); StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field LPTSTR cmdArgs = "name@example.com"; 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;
}
Hey one more thing, if I pass my cmdArgs like this:
// a space as the first character
LPTSTR cmdArgs = " manzoor10@gmail.com";I get the error:
Object reference not set to an instance of an object
then CreateProcess returns TRUE but my target process isn't executed.
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.
modified on Thursday, June 10, 2010 2:13 AM
PROCESS_INFORMATION pi; ZeroMemory (&pi, sizeof (pi)); STARTUPINFOA si; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW; //si.wShowWindow = SW_HIDE; si.wShowWindow = SW_SHOW; CreateProcessA (NULL, cmd, 0, 0, 0, CREATE_NO_WINDOW, 0, 0, &si, &pi);
-
PROCESS_INFORMATION pi; ZeroMemory (&pi, sizeof (pi)); STARTUPINFOA si; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW; //si.wShowWindow = SW_HIDE; si.wShowWindow = SW_SHOW; CreateProcessA (NULL, cmd, 0, 0, 0, CREATE_NO_WINDOW, 0, 0, &si, &pi);
tns_ranjith wrote:
STARTUPINFOA
tns_ranjith wrote:
CreateProcessA
Why?
-
tns_ranjith wrote:
STARTUPINFOA
tns_ranjith wrote:
CreateProcessA
Why?
You shouldn't be giving him any importance (take a look at some of his recent posts). You could just mark it down instead.
It is a crappy thing, but it's life -^ Carlo Pallini
-
You shouldn't be giving him any importance (take a look at some of his recent posts). You could just mark it down instead.
It is a crappy thing, but it's life -^ Carlo Pallini
Oh, I thought he was trying to make a point.
-
tns_ranjith wrote:
STARTUPINFOA
tns_ranjith wrote:
CreateProcessA
Why?
for unicode project u want to use non unicode characters support..