School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,156 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,987 people online right now. Registration is fast and FREE... Join Now!



CreateProcess Exception

CreateProcess Exception Rate Topic: -----

#1 astudio66  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 5
  • Joined: 14-February 09


Dream Kudos: 0

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
Was This Post Helpful? 0
  • +
  • -


#2 bsaunders  Icon User is offline

  • D.I.C Addict
  • PipPipPipPip
  • Group: Members
  • Posts: 571
  • Joined: 18-January 09


Dream Kudos: 0

Posted 14 February 2009 - 02:38 AM

May you post your code with the call to CreateProcess?
Was This Post Helpful? 0
  • +
  • -

#3 astudio  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 4
  • Joined: 15-June 08


Dream Kudos: 0

Posted 18 February 2009 - 10:38 AM

this is my code
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

Was This Post Helpful? 0
  • +
  • -

#4 bsaunders  Icon User is offline

  • D.I.C Addict
  • PipPipPipPip
  • Group: Members
  • Posts: 571
  • Joined: 18-January 09


Dream Kudos: 0

Posted 18 February 2009 - 02:38 PM

I think a size of 10 bytes for si is a bit small.

What happens if you changed cb to:

si.cb = sizeof(STARTUPINFO);?
Was This Post Helpful? 0
  • +
  • -

#5 astudio66  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 5
  • Joined: 14-February 09


Dream Kudos: 0

Posted 02 March 2009 - 03:04 AM

yes 10 is small I changed my code to this:
#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 ? :blink: :blink:
Was This Post Helpful? 0
  • +
  • -

#6 bsaunders  Icon User is offline

  • D.I.C Addict
  • PipPipPipPip
  • Group: Members
  • Posts: 571
  • Joined: 18-January 09


Dream Kudos: 0

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.
		π );

Was This Post Helpful? 0
  • +
  • -

#7 horace  Icon User is offline

  • D.I.C Lover
  • Icon
  • Group: Expert
  • Posts: 1,603
  • Joined: 25-October 06


Dream Kudos: 50

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 );


Was This Post Helpful? 0
  • +
  • -

#8 astudio66  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 5
  • Joined: 14-February 09


Dream Kudos: 0

Posted 05 March 2009 - 07:20 AM

thanX for your helps but I cant fix that this statement (CreateProcess)is very complex :angry:
Was This Post Helpful? 0
  • +
  • -

#9 horace  Icon User is offline

  • D.I.C Lover
  • Icon
  • Group: Expert
  • Posts: 1,603
  • Joined: 25-October 06


Dream Kudos: 50

Posted 05 March 2009 - 09:41 AM

View Postastudio66, on 5 Mar, 2009 - 02:20 PM, said:

thanX for your helps but I cant fix that this statement (CreateProcess)is very complex :angry:

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


Was This Post Helpful? 0
  • +
  • -

#10 jeff666  Icon User is offline

  • D.I.C Head
  • PipPip
  • Group: Members
  • Posts: 193
  • Joined: 30-December 08


Dream Kudos: 0

Posted 05 March 2009 - 09:57 AM

Why don't you copy-paste MSDN samples ?!!!
There are hundred ones !
Was This Post Helpful? 0
  • +
  • -

#11 astudio66  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 5
  • Joined: 14-February 09


Dream Kudos: 0

Posted 07 March 2009 - 01:06 AM

yes I did it!(copy-paste)
I think this code have a problem in pointers. I am java programmer and in java we have pointers like in c++
thanX for your helps
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month