How to launch a EXE file from within the VC++ code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • helloitsme
    New Member
    • Oct 2006
    • 20

    How to launch a EXE file from within the VC++ code?

    Hello!

    Could someone please help me figure out how to run an executable file from within the soure code and pass the commands to the exe file to be launched!

    I was trying to use tools.shell, but it gives me error...

    please help....
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Call CreateProcess

    Comment

    • helloitsme
      New Member
      • Oct 2006
      • 20

      #3
      Thanx a lot Banfa for your reply!

      I tried using CreateProcess. But I keep getting the error "Unhandled exception at 0x7c825352 in InventoryFiles. exe: 0xC0000005: Access violation writing location 0x006a3ce2.".

      I dont know where the problem lies.

      the part of code I used for my testing of this function is -
      -----------------------------------------
      STARTUPINFO si;
      PROCESS_INFORMA TION pi;

      ZeroMemory( &si, sizeof(si) );
      si.cb = sizeof(si);
      ZeroMemory( &pi, sizeof(pi) );

      CreateProcess( NULL, // No module name (use command line)
      TEXT("NOTEPAD") , // 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_INFORMA TION structure

      -------------------------------------------------------------------

      Kindly point out my error...

      Thank you....

      Comment

      • Jagdish
        New Member
        • Oct 2006
        • 2

        #4
        You can use ShellExecute Function to execute any exe from VC++ code.

        Hope that will help you.

        Jagdish

        Comment

        • helloitsme
          New Member
          • Oct 2006
          • 20

          #5
          Hello Jagdish!

          Thank you for your reply!

          Can you please tell me how to open the command prompt using shellexecute...

          thank you once again....

          Comment

          • helloitsme
            New Member
            • Oct 2006
            • 20

            #6
            Hello !

            to conitnue my previous post, below is the part of the code where I am trying to launch notepad through command prompt using shellexecute.

            with this, the commandprompt does come up, but the text "NOTEPAD" is not passed to the command window. please help me do that...

            ............... ............... ............... ............... .........
            int x = (int)ShellExecu te(NULL, NULL, L"C:\\WINDOWS\\ system32\\cmd.e xe", L"NOTEPAD", NULL, SW_SHOWNORMAL);

            ............... ............... ............... ...

            thanx a ton....

            Comment

            Working...