Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Process handling

Process handling

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mpapeo
    wrote on last edited by
    #1

    I have my small program which creates process, but now i want to manipulate more than one process at a time. Is that possible? Like i have created a notepad process and later while notepad is running i create another process cmd.exe, can i suspend them all one after the other or shut them consecutively maybe by specifying process id,s or handles -oam-

    M 1 Reply Last reply
    0
    • M mpapeo

      I have my small program which creates process, but now i want to manipulate more than one process at a time. Is that possible? Like i have created a notepad process and later while notepad is running i create another process cmd.exe, can i suspend them all one after the other or shut them consecutively maybe by specifying process id,s or handles -oam-

      M Offline
      M Offline
      mark novak
      wrote on last edited by
      #2

      Aww man you can do all kinds of rad things with processes. Pretty much everything that Task Manager can do you can do. What you want to do is call CreateProcess() and pay attention to the last argument, a PROCESS_INFORMATION structure which has the hProcess handle. With that your free to call functions like TerminateProcess() and SuspendThread(). However TerminateProcess() is pretty drastic and does not guarantee that anything will be freed and the process may need to run critical cleanup code. TerminateProcess() is like shutting a program off by unplugging the power. You could see if a process is associated with a window by calling EnumWindows() and comparing the ProcessId, which you can get from GetWindowThreadProcessId(). Check out http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/process_and_thread_functions.asp[^] for Process/Thread manipulation.

      M 1 Reply Last reply
      0
      • M mark novak

        Aww man you can do all kinds of rad things with processes. Pretty much everything that Task Manager can do you can do. What you want to do is call CreateProcess() and pay attention to the last argument, a PROCESS_INFORMATION structure which has the hProcess handle. With that your free to call functions like TerminateProcess() and SuspendThread(). However TerminateProcess() is pretty drastic and does not guarantee that anything will be freed and the process may need to run critical cleanup code. TerminateProcess() is like shutting a program off by unplugging the power. You could see if a process is associated with a window by calling EnumWindows() and comparing the ProcessId, which you can get from GetWindowThreadProcessId(). Check out http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/process_and_thread_functions.asp[^] for Process/Thread manipulation.

        M Offline
        M Offline
        mpapeo
        wrote on last edited by
        #3

        Well my question lies in how to specify the handle or the process id of one the processes i have created to shut it down or suspend it that particular process. Pliz give me a segment code if you have. #include #include #include #include #include #include typedef struct _iobuf FILE; #include #include #include 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: Suspend the process\t="); printf ("\n=\t 3: Resume the process\t=");//recreate the process printf ("\n=\t 4: System Information\t="); printf ("\n=========================================\n"); printf ("\n"); printf("\nEnter choice (1-4): "); 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*/ HANDLE hProcess; HANDLE hThread = 0; DWORD NumberOfBytesRead = 0; DWORD baseaddr = 0; DWORD lpAddr = 0; PMEMORY_BASIC_INFORMATION lpBuffer = 0; DWORD dwLength = 200000; DWORD flNewProtect =0; PDWORD lpflOldProtect = 0; DWORD dwSize =0; LPCVOID lpBaseAddress = 0; DWORD nSize = 0; // MEMORY_BASIC_INFORMATION mbi; LPDWORD lpNumberOfBytesWritten = 0; TCHAR lpApplicationName[_MAX_PATH]=""; SYSTEM_INFO sinfo; LPDWORD lpExitCode = 0; // DWORD pid; // LPVOID base; HWND hWnd = 0; DWORD dwProcessID = 0; UINT GetBase(); LPCONTEXT lpContext = 0; //CONST CONTEXT *lpContext; int nRet = 0; // char *state; unsigned int regnum = 0; //******************************************** char* ans=""; int choice; while((choice = menu())!=5) { switch (choice) { case 1: GetStartupInfo(&si); lpAddr = 0; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); printf("Enter process you want to execute: ",lpApplicationName); scanf ("%s",lpApplicationName); printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID CreateProcess(NULL, /* lpApplicationName */ lpApplicationName, /* lpCommandLine assumes to use curent process directory*/ NULL, /* lpsaProcess */ NULL, /* lpsaThread */ FALSE, /* bInheritHandles */ CREATE_NEW_CONSOLE

        M 1 Reply Last reply
        0
        • M mpapeo

          Well my question lies in how to specify the handle or the process id of one the processes i have created to shut it down or suspend it that particular process. Pliz give me a segment code if you have. #include #include #include #include #include #include typedef struct _iobuf FILE; #include #include #include 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: Suspend the process\t="); printf ("\n=\t 3: Resume the process\t=");//recreate the process printf ("\n=\t 4: System Information\t="); printf ("\n=========================================\n"); printf ("\n"); printf("\nEnter choice (1-4): "); 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*/ HANDLE hProcess; HANDLE hThread = 0; DWORD NumberOfBytesRead = 0; DWORD baseaddr = 0; DWORD lpAddr = 0; PMEMORY_BASIC_INFORMATION lpBuffer = 0; DWORD dwLength = 200000; DWORD flNewProtect =0; PDWORD lpflOldProtect = 0; DWORD dwSize =0; LPCVOID lpBaseAddress = 0; DWORD nSize = 0; // MEMORY_BASIC_INFORMATION mbi; LPDWORD lpNumberOfBytesWritten = 0; TCHAR lpApplicationName[_MAX_PATH]=""; SYSTEM_INFO sinfo; LPDWORD lpExitCode = 0; // DWORD pid; // LPVOID base; HWND hWnd = 0; DWORD dwProcessID = 0; UINT GetBase(); LPCONTEXT lpContext = 0; //CONST CONTEXT *lpContext; int nRet = 0; // char *state; unsigned int regnum = 0; //******************************************** char* ans=""; int choice; while((choice = menu())!=5) { switch (choice) { case 1: GetStartupInfo(&si); lpAddr = 0; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); printf("Enter process you want to execute: ",lpApplicationName); scanf ("%s",lpApplicationName); printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID CreateProcess(NULL, /* lpApplicationName */ lpApplicationName, /* lpCommandLine assumes to use curent process directory*/ NULL, /* lpsaProcess */ NULL, /* lpsaThread */ FALSE, /* bInheritHandles */ CREATE_NEW_CONSOLE

          M Offline
          M Offline
          mark novak
          wrote on last edited by
          #4

          You code looks fine, your passing the handles of the process and thread from the PROCESS_INFORMATION structure that gets filled out when you call CreateProcess(). Perhaps make sure that these calls are succeeding by checking the return values. If you wanted to keep track of more then one process then you could use a container class like MFC's CArray or CList or STL's vector or list.

          M 1 Reply Last reply
          0
          • M mark novak

            You code looks fine, your passing the handles of the process and thread from the PROCESS_INFORMATION structure that gets filled out when you call CreateProcess(). Perhaps make sure that these calls are succeeding by checking the return values. If you wanted to keep track of more then one process then you could use a container class like MFC's CArray or CList or STL's vector or list.

            M Offline
            M Offline
            mpapeo
            wrote on last edited by
            #5

            Mark Petrik Sosa wrote: Perhaps make sure that these calls are succeeding by checking the return values. If you wanted to keep track of more then one process then you could use a container class like MFC's CArray or CList or STL's vector or list. I don't have any idea about MFC arrays because i am using C unless if they can work in c code. But i have no idea with MFC or CList nor STL vector. You can give me a go ahead or segment code to handle it -oam-

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups