Thread: Run .exe from a c++ program

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    2

    Cool Run .exe from a c++ program

    How can we do this. How can we run .exe from a c++ program.

    Suppose I have a file located in C: name "abc.exe".

    Now how will I execute this "abc.exe" file from a c++ program????????

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    55
    Assuming Windows, this fires up notepad:
    Code:
    HANDLE open_notepad()
    {
        STARTUPINFO si = {sizeof( STARTUPINFO)};
        PROCESS_INFORMATION pi;
        CreateProcess( "c:\\windows\\notepad.exe",
                       0, 0, 0, 0, 0, 0, 0, &si, &pi);
        return pi.hProcess;
    }

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    59
    Or perheps something like this if you do managed:

    Code:
    System::Diagnostics::Process::Start("C:\\abc.exe");

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Managed is not C++. C++/CLI is a managed language, and usually they mean "native" C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    You can also use the standard system() function, or you can use popen(), or one of the spawn() functions...
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help on making program run more efficiently
    By peeweearies in forum C Programming
    Replies: 2
    Last Post: 03-23-2009, 02:01 AM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  3. Re-doing a C program to run in Win2000 or XP
    By fifi in forum C Programming
    Replies: 5
    Last Post: 08-17-2007, 05:32 PM
  4. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  5. Help me with my basic program, nothing I create will run
    By Ravens'sWrath in forum C Programming
    Replies: 31
    Last Post: 05-13-2007, 02:35 AM