CreateProcess Exception
Page 1 of 1
CreateProcess Exception
#1
Posted 14 February 2009 - 12:46 AM
hello
I am new in c++ I have problem with CreateProcess when I use it in my project an exception stop my program
exception:
------------------------------------
Unhandled exception at 0x7c825352 in test.exe: 0xC0000005: Access violation writing location 0x00403658.
-------------------------------------
and then print in output window(in visual C++ IDE):
---------------------------------------------------
'test.exe': Loaded 'D:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'test.exe': Loaded 'D:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'test.exe': Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcr80d.dll', No symbols loaded.
'test.exe': Loaded 'D:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
----------------------------------------------------
any one can help me!
thanks
I am new in c++ I have problem with CreateProcess when I use it in my project an exception stop my program
exception:
------------------------------------
Unhandled exception at 0x7c825352 in test.exe: 0xC0000005: Access violation writing location 0x00403658.
-------------------------------------
and then print in output window(in visual C++ IDE):
---------------------------------------------------
'test.exe': Loaded 'D:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'test.exe': Loaded 'D:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'test.exe': Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcr80d.dll', No symbols loaded.
'test.exe': Loaded 'D:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
----------------------------------------------------
any one can help me!
thanks
#3
Posted 18 February 2009 - 10:38 AM
this is my code
*** MOD EDIT: Fixed code tags ***
void main( VOID )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &pi, sizeof(pi) );
ZeroMemory( &si, sizeof(si) );
si.cb = 10;//sizeof(si);
//system("tracert -d www.yahoo.com");
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
TEXT("C:\\Documents and Settings\\AHMAD> tracert -d www.yahoo.com"), // 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.
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
getchar();
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
*** MOD EDIT: Fixed code tags ***
This post has been edited by JackOfAllTrades: 02 March 2009 - 05:59 AM
#5
Posted 02 March 2009 - 03:04 AM
yes 10 is small I changed my code to this:
in this case program run but GetLastError function return 2 and command dose not execute I dont khnow why ?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
#pragma comment (lib, "Ws2_32.lib" )
#pragma comment (lib, "Kernel32.lib" )
void main( VOID )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
int spi=sizeof(pi);
int ssi= sizeof(si);
//ZeroMemory( π,spi );
//ZeroMemory( &si, ssi);
si.cb=sizeof(STARTUPINFO); //sizeof(si);
//system("tracert -d www.yahoo.com");
STARTUPINFO* ptr=&si;
int b=0;
// Start the child process.
b=CreateProcess(L"tracert.exe -d www.yahoo.com" , // No module name (use command line).
NULL, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
true, // Set handle inheritance to FALSE.
NORMAL_PRIORITY_CLASS, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
ptr, // Pointer to STARTUPINFO structure.
π );
if( b==0) // Pointer to PROCESS_INFORMATION structure.
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
getchar();
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
[code]in this case program run but GetLastError function return 2 and command dose not execute I dont khnow why ?
#6
Posted 02 March 2009 - 03:37 AM
What happens if you move the module name and command line to the second argument instead of the first?
b=CreateProcess(NULL, L"tracert.exe -d www.yahoo.com", // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. true, // Set handle inheritance to FALSE. NORMAL_PRIORITY_CLASS, // No creation flags. NULL, // Use parent's environment block. NULL, // Use parent's starting directory. ptr, // Pointer to STARTUPINFO structure. π );
#7
Posted 02 March 2009 - 06:22 AM
try
STARTUPINFO si;
PROCESS_INFORMATION pi;
int spi=sizeof(pi);
int ssi= sizeof(si);
ZeroMemory( &si, sizeof(si) );
si.cb=sizeof(STARTUPINFO); //sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
int b=0;
// Start the child process.
b=CreateProcess("tracert.exe ",
"-d www.yahoo.com" , // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
0, // Set handle inheritance to FALSE.
NORMAL_PRIORITY_CLASS, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi );
#9
Posted 05 March 2009 - 09:41 AM
astudio66, on 5 Mar, 2009 - 02:20 PM, said:
thanX for your helps but I cant fix that this statement (CreateProcess)is very complex 
say you have a program tracert.cpp - build it
#include <iostream.h>
#include <string.h>
//----------------------------------------------------------------------------//
// function main with parameters //
// argc - number of elements in array argv //
// argv - an array of pointers to strings //
int main(int argc, char *argv[])
{
cout << "\ntracert - number of parameters in command line is " << argc;
for (int index = 0; index < argc; index++)
{
cout << "\n parameter " << index << " is " << argv[index];
}
cout << endl;
return 0;
}
and you run
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
#pragma comment (lib, "Ws2_32.lib" )
#pragma comment (lib, "Kernel32.lib" )
int main( VOID )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
int spi=sizeof(pi);
int ssi= sizeof(si);
ZeroMemory( &si, sizeof(si) );
si.cb=sizeof(STARTUPINFO); //sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
int b=0;
printf( "\nCalling CreateProcess \n" );
// Start the child process.
b=CreateProcess("tracert.exe ",
"-d www.yahoo.com" , // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
0, // Set handle inheritance to FALSE.
NORMAL_PRIORITY_CLASS, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi );
if( b==0) // Pointer to PROCESS_INFORMATION structure.
{
printf( "CreateProcess failed %d (%ld).\n", b, GetLastError() );
}
printf( "\nCreateProcess OK\n" );
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
printf( "\nChild process completed\n" );
// Close process and thread handles.
getchar();
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
and the output is
tracert - number of parameters in command line is 2 parameter 0 is -d parameter 1 is www.yahoo.com Calling CreateProcess CreateProcess OK Child process completed
Page 1 of 1

Start a new topic
Add Reply




MultiQuote
| 


