CreateProcess Method
-
Hi, I tried to create a process(notepad.exe) using the CreateProcess method. But the method failes throwing a Exception. Could any one please tell why this following code snippet is failing. PROCESS_INFORMATION pProcessInfo; BOOL bStatus = CreateProcess("C:\\WINDOWS\\Notepad.exe",NULL,NULL,NULL,NULL,CREATE_NEW_CONSOLE,NULL,NULL,NULL,&pProcessInfo); Regards
-
Hi, I tried to create a process(notepad.exe) using the CreateProcess method. But the method failes throwing a Exception. Could any one please tell why this following code snippet is failing. PROCESS_INFORMATION pProcessInfo; BOOL bStatus = CreateProcess("C:\\WINDOWS\\Notepad.exe",NULL,NULL,NULL,NULL,CREATE_NEW_CONSOLE,NULL,NULL,NULL,&pProcessInfo); Regards
PROCESS_INFORMATION pProcessInfo; STARTUPINFO si= {0}; si.cb = sizeof(STARTUPINFO); BOOL bStatus = CreateProcess("c:\\WINDOWS\\Notepad.exe",NULL,NULL,NULL,NULL,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pProcessInfo);
-
PROCESS_INFORMATION pProcessInfo; STARTUPINFO si= {0}; si.cb = sizeof(STARTUPINFO); BOOL bStatus = CreateProcess("c:\\WINDOWS\\Notepad.exe",NULL,NULL,NULL,NULL,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pProcessInfo);
WhiteSky wrote:
("c:\\WINDOWS\\Notepad.exe",NULL,NULL,NULL,NULL,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pProcessInfo);
The Windows directory should not be hard coded.
-
Hi, I tried to create a process(notepad.exe) using the CreateProcess method. But the method failes throwing a Exception. Could any one please tell why this following code snippet is failing. PROCESS_INFORMATION pProcessInfo; BOOL bStatus = CreateProcess("C:\\WINDOWS\\Notepad.exe",NULL,NULL,NULL,NULL,CREATE_NEW_CONSOLE,NULL,NULL,NULL,&pProcessInfo); Regards
You're not passing a
STARTUPINFO
struct.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
Hi, I tried to create a process(notepad.exe) using the CreateProcess method. But the method failes throwing a Exception. Could any one please tell why this following code snippet is failing. PROCESS_INFORMATION pProcessInfo; BOOL bStatus = CreateProcess("C:\\WINDOWS\\Notepad.exe",NULL,NULL,NULL,NULL,CREATE_NEW_CONSOLE,NULL,NULL,NULL,&pProcessInfo); Regards
Hi Subramaniam, I don't know what's wrong with your code but I did it like this:
STARTUPINFO si; PROCESS_INFORMATION pi; // Start the child process. CreateProcess( NULL, // No module name (use command line). TEXT("C:\\Windows\\system32\\notepad.exe"), // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. FALSE, // Set handle inheritance to FALSE. 0, // No creation flags. NULL, // Use parent's environment block. NULL, // Use parent's starting directory. &si, // Pointer to STARTUPINFO structure. &pi ); // Pointer to PROCESS_INFORMATION structure.
It works on my computer. Best regards, Chris -
Hi, I tried to create a process(notepad.exe) using the CreateProcess method. But the method failes throwing a Exception. Could any one please tell why this following code snippet is failing. PROCESS_INFORMATION pProcessInfo; BOOL bStatus = CreateProcess("C:\\WINDOWS\\Notepad.exe",NULL,NULL,NULL,NULL,CREATE_NEW_CONSOLE,NULL,NULL,NULL,&pProcessInfo); Regards
When you do get it to work remember no to leak
HANDLE
s. After theCreateProcess
call you need to close someHANDLES
it returns if you don't plan on using them:PROCESS_INFORMATION pi; BOOL bOK = CreateProcess(..., &pi); if (bOK) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); }
Not closing these handles is a common mistake people calling
CreateProcess
make. Also you use the wart "p" on the variable "pProcessInfo" - This is normally used for pointers. You'll confuse people using it on a variable that isn't a pointer. Steve -
When you do get it to work remember no to leak
HANDLE
s. After theCreateProcess
call you need to close someHANDLES
it returns if you don't plan on using them:PROCESS_INFORMATION pi; BOOL bOK = CreateProcess(..., &pi); if (bOK) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); }
Not closing these handles is a common mistake people calling
CreateProcess
make. Also you use the wart "p" on the variable "pProcessInfo" - This is normally used for pointers. You'll confuse people using it on a variable that isn't a pointer. Steve -
Hi All, First of all many thanks to all who have given their valuable suggestion. I am not getting the Exception now but I get an Access Violation error like this in my output window and my notepad doesnt launch.
ChristopherAtCodeProject wrote:
First-chance exception in Threading Sample.exe (NTDLL.DLL): 0xC0000005: Access Violation.
First-chance exception in Threading Sample.exe (NTDLL.DLL): 0xC0000005: Access Violation. Any help on this please. Do I need to give some security descriptors or something. To the best of my knowledge its not required I suppose as even if we pass NULL to them it will consider the default Security. Many Thanks
-
Hi All, First of all many thanks to all who have given their valuable suggestion. I am not getting the Exception now but I get an Access Violation error like this in my output window and my notepad doesnt launch.
ChristopherAtCodeProject wrote:
First-chance exception in Threading Sample.exe (NTDLL.DLL): 0xC0000005: Access Violation.
First-chance exception in Threading Sample.exe (NTDLL.DLL): 0xC0000005: Access Violation. Any help on this please. Do I need to give some security descriptors or something. To the best of my knowledge its not required I suppose as even if we pass NULL to them it will consider the default Security. Many Thanks
Hi All, Its working fine now. I had to fill in the STARTUPINFO struture. Thanks