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. CreateProcess Method

CreateProcess Method

Scheduled Pinned Locked Moved C / C++ / MFC
9 Posts 6 Posters 1 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.
  • S Offline
    S Offline
    Subramaniam s V
    wrote on last edited by
    #1

    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

    H M C S 4 Replies Last reply
    0
    • S Subramaniam s V

      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

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

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

      S 1 Reply Last reply
      0
      • H Hamid Taebi

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

        S Offline
        S Offline
        SilentSilent
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Subramaniam s V

          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

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          You're not passing a STARTUPINFO struct.

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

          1 Reply Last reply
          0
          • S Subramaniam s V

            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

            C Offline
            C Offline
            Chris Gao
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • S Subramaniam s V

              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

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              When you do get it to work remember no to leak HANDLEs. After the CreateProcess call you need to close some HANDLES 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

              C 1 Reply Last reply
              0
              • S Stephen Hewitt

                When you do get it to work remember no to leak HANDLEs. After the CreateProcess call you need to close some HANDLES 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

                C Offline
                C Offline
                Chris Gao
                wrote on last edited by
                #7

                Hi Steve, I even didn't think about this at all! Thanks!! Chris

                S 1 Reply Last reply
                0
                • C Chris Gao

                  Hi Steve, I even didn't think about this at all! Thanks!! Chris

                  S Offline
                  S Offline
                  Subramaniam s V
                  wrote on last edited by
                  #8

                  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

                  S 1 Reply Last reply
                  0
                  • S Subramaniam s V

                    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

                    S Offline
                    S Offline
                    Subramaniam s V
                    wrote on last edited by
                    #9

                    Hi All, Its working fine now. I had to fill in the STARTUPINFO struture. Thanks

                    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