program crushes!!
-
I have a little menu here which i want to execute my functions using it. So i have problems in entering the process like notepad which i want to create, but then it crushes. How can i declare the variable which will take care of the input process, because i didn't want to include it in the commandline when running. Part of my code is below
#include #include #include #include #include LPVOID lpMsgBuf; int menu(void) { int choice; printf ("\n"); printf ("*****************************************\n"); printf ("*\t\t\t\t\t*\n*\tCHECKPOINTING SYSTEM \t\t*\n"); printf ("========================================="); printf ("\n=\t 1: Create a process \t="); printf ("\n=\t 2: Shutdown the process\t="); printf ("\n=========================================\n"); printf ("\n"); printf("\nEnter choice (1-2): "); scanf("%d", &choice); return choice; } int main(int argc, char **argv) { PROCESS_INFORMATION pi ; /* filled in by CreateProcess */ STARTUPINFO si; /* startup info for the new process*/ LPDWORD lpExitCode = 0; HANDLE hProcess ; DWORD baseaddr = 0; DWORD error = GetLastError(); LPCTSTR lpApplicationName=""; int choice; menu(); while((choice = menu())!=3) { switch (choice) { case 1: printf("Enter process you want to execute: ",lpApplicationName); scanf ("%s",lpApplicationName); printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID GetStartupInfo(&si); CreateProcess(NULL, /* lpApplicationName */ argv[1], /* lpCommandLine assumes to use curent process directory*/ NULL, /* lpsaProcess */ NULL, /* lpsaThread */ FALSE, /* bInheritHandles */ CREATE_NEW_CONSOLE, /* dwCreationFlags */ NULL, /* lpEnvironment */ NULL, /* lpCurDir */ &si, /* lpStartupInfo */ &pi /* lpProcInfo */ ); hProcess = pi.hProcess; printf("New Process ID: %d ",pi.dwProcessId); printf("has started \n"); break; case 2: TerminateProcess(pi.hProcess, GetExitCodeProcess(hProcess,lpExitCode )); GetLastError(); break; default: printf("\nInvalid choice: "); }//while } return(0); }
oam -
I have a little menu here which i want to execute my functions using it. So i have problems in entering the process like notepad which i want to create, but then it crushes. How can i declare the variable which will take care of the input process, because i didn't want to include it in the commandline when running. Part of my code is below
#include #include #include #include #include LPVOID lpMsgBuf; int menu(void) { int choice; printf ("\n"); printf ("*****************************************\n"); printf ("*\t\t\t\t\t*\n*\tCHECKPOINTING SYSTEM \t\t*\n"); printf ("========================================="); printf ("\n=\t 1: Create a process \t="); printf ("\n=\t 2: Shutdown the process\t="); printf ("\n=========================================\n"); printf ("\n"); printf("\nEnter choice (1-2): "); scanf("%d", &choice); return choice; } int main(int argc, char **argv) { PROCESS_INFORMATION pi ; /* filled in by CreateProcess */ STARTUPINFO si; /* startup info for the new process*/ LPDWORD lpExitCode = 0; HANDLE hProcess ; DWORD baseaddr = 0; DWORD error = GetLastError(); LPCTSTR lpApplicationName=""; int choice; menu(); while((choice = menu())!=3) { switch (choice) { case 1: printf("Enter process you want to execute: ",lpApplicationName); scanf ("%s",lpApplicationName); printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID GetStartupInfo(&si); CreateProcess(NULL, /* lpApplicationName */ argv[1], /* lpCommandLine assumes to use curent process directory*/ NULL, /* lpsaProcess */ NULL, /* lpsaThread */ FALSE, /* bInheritHandles */ CREATE_NEW_CONSOLE, /* dwCreationFlags */ NULL, /* lpEnvironment */ NULL, /* lpCurDir */ &si, /* lpStartupInfo */ &pi /* lpProcInfo */ ); hProcess = pi.hProcess; printf("New Process ID: %d ",pi.dwProcessId); printf("has started \n"); break; case 2: TerminateProcess(pi.hProcess, GetExitCodeProcess(hProcess,lpExitCode )); GetLastError(); break; default: printf("\nInvalid choice: "); }//while } return(0); }
oamTry this:
#include "stdafx.h" #include <stdio.h> int menu(void) { int choice; printf ("\n"); printf ("*****************************************\n"); printf ("*\t\t\t\t\t*\n*\tCHECKPOINTING SYSTEM \t\t*\n"); printf ("========================================="); printf ("\n=\t 1: Create a process \t="); printf ("\n=\t 2: Shutdown the process\t="); printf ("\n=========================================\n"); printf ("\n"); printf("\nEnter choice (1-2): "); scanf("%d", &choice); return choice; } void main(int argc, char **argv) { PROCESS_INFORMATION pi ; /* filled in by CreateProcess */ STARTUPINFO si; /* startup info for the new process*/ HANDLE hProcess; TCHAR lpApplicationName[100]=""; int choice; while((choice = menu())!=3) { switch (choice) { case 1: printf("Enter process you want to execute: ",lpApplicationName); scanf ("%s",lpApplicationName); printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID GetStartupInfo(&si); CreateProcess(NULL, /* lpApplicationName */ lpApplicationName, /* lpCommandLine assumes to use curent process directory*/ NULL, /* lpsaProcess */ NULL, /* lpsaThread */ FALSE, /* bInheritHandles */ CREATE_NEW_CONSOLE, /* dwCreationFlags */ NULL, /* lpEnvironment */ NULL, /* lpCurDir */ &si, /* lpStartupInfo */ &pi /* lpProcInfo */ ); hProcess = pi.hProcess; printf("New Process ID: %d ",pi.dwProcessId); printf("has started \n"); break; case 2: TerminateProcess(pi.hProcess, 0); break; default: printf("\nInvalid choice: "); } } }
And don't be as lazy as to believe anything you see...
"though nothing will keep us together we can beat them for ever and ever" rechi
-
Try this:
#include "stdafx.h" #include <stdio.h> int menu(void) { int choice; printf ("\n"); printf ("*****************************************\n"); printf ("*\t\t\t\t\t*\n*\tCHECKPOINTING SYSTEM \t\t*\n"); printf ("========================================="); printf ("\n=\t 1: Create a process \t="); printf ("\n=\t 2: Shutdown the process\t="); printf ("\n=========================================\n"); printf ("\n"); printf("\nEnter choice (1-2): "); scanf("%d", &choice); return choice; } void main(int argc, char **argv) { PROCESS_INFORMATION pi ; /* filled in by CreateProcess */ STARTUPINFO si; /* startup info for the new process*/ HANDLE hProcess; TCHAR lpApplicationName[100]=""; int choice; while((choice = menu())!=3) { switch (choice) { case 1: printf("Enter process you want to execute: ",lpApplicationName); scanf ("%s",lpApplicationName); printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID GetStartupInfo(&si); CreateProcess(NULL, /* lpApplicationName */ lpApplicationName, /* lpCommandLine assumes to use curent process directory*/ NULL, /* lpsaProcess */ NULL, /* lpsaThread */ FALSE, /* bInheritHandles */ CREATE_NEW_CONSOLE, /* dwCreationFlags */ NULL, /* lpEnvironment */ NULL, /* lpCurDir */ &si, /* lpStartupInfo */ &pi /* lpProcInfo */ ); hProcess = pi.hProcess; printf("New Process ID: %d ",pi.dwProcessId); printf("has started \n"); break; case 2: TerminateProcess(pi.hProcess, 0); break; default: printf("\nInvalid choice: "); } } }
And don't be as lazy as to believe anything you see...
"though nothing will keep us together we can beat them for ever and ever" rechi
Im sorry im using C language and now i'm having a problem with the header file stdafx.h because i think it works in C++. the error i'm getting shows this after adding the header file to the project.
Compiling... pro.c c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(15) : fatal error C1189: #error : MFC requires C++ compilation (use a .cpp suffix) Error executing cl.exe. pro.obj - 1 error(s), 0 warning(s)
oam -
Im sorry im using C language and now i'm having a problem with the header file stdafx.h because i think it works in C++. the error i'm getting shows this after adding the header file to the project.
Compiling... pro.c c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(15) : fatal error C1189: #error : MFC requires C++ compilation (use a .cpp suffix) Error executing cl.exe. pro.obj - 1 error(s), 0 warning(s)
oam -
Comment the
#include "stdafx.h"
line.
"though nothing will keep us together we can beat them for ever and ever" rechi
-
well now it works even after re-including the header file. But now it does not create the notepad process and im amazed that its ID is -858993460 though it doesn't appear oam
It does. Check out the source again and look for
GetStartupInfo(&si)
. Reinsert it into your code. No, wait! Just replace it with:ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) );
"though nothing will keep us together we can beat them for ever and ever" rechi
-
It does. Check out the source again and look for
GetStartupInfo(&si)
. Reinsert it into your code. No, wait! Just replace it with:ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) );
"though nothing will keep us together we can beat them for ever and ever" rechi
-
I replaced the code lines you suggested but still it doesn't showup the process running, i.e. notepad or cmd. I tried to tackle it anyhow but still... and what i am concern with is that the process ID it shows is the same everytime i try to create it oam