how to launch exe from within program

This is a discussion on how to launch exe from within program within the C++ Programming forums, part of the General Programming Boards category; Hi, I have searched the forums and across google, for code to simply lauch another exe. Help appreciated...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    22

    how to launch exe from within program

    Hi,
    I have searched the forums and across google, for code to simply lauch another exe.

    Help appreciated
    Last edited by jonezy; 06-19-2005 at 02:30 PM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    There's an entry in the FAQ (there's a "FAQ" button at the top of this page) that does exactly what you're looking for.

    How do I run a program from within a program?

    **Beaten by Salem.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    3

    Post

    this should work , only need to add #include <windows.h> at beginning.

    Code:
    int Exec(char szPath[])
    {  
      PROCESS_INFORMATION pif;
      STARTUPINFO si;
      ZeroMemory(&si,sizeof(si));
      si.cb = sizeof(si);
      BOOL bRet = CreateProcess(szPath,NULL,NULL,NULL,FALSE,0,NULL,NULL,&si,&pif);
      if (bRet == FALSE) {
            MessageBox(HWND_DESKTOP,"Unable to start program","",MB_OK);
            return 1;
         }
      CloseHandle(pif.hProcess);
      CloseHandle(pif.hThread);
      return 0;
    }
    an exemple : Exec( "C:\\temp\\hello.exe" );
    do not forget the double \ , or it's will not work.

  5. #5
    Registered User
    Join Date
    Apr 2005
    Posts
    22
    thanks, slilly me lol the tutorials were the only places that i didnt check. The tutorials seemed very complex to look at so i am goin to try you reply wejav 2nite tand then i will get back to you.

  6. #6
    Registered User
    Join Date
    Apr 2005
    Posts
    22
    I do not no y this code does not work.

    Code:
    #include <windows.h>
    
    int Exec(char szPath[])
    {  
      PROCESS_INFORMATION pif;
      STARTUPINFO si;
      ZeroMemory(&si,sizeof(si));
      si.cb = sizeof(si);
      BOOL bRet = CreateProcess(szPath,NULL,NULL,NULL,FALSE,0,NULL,NULL,&si,&pif);
      if (bRet == FALSE) {
            MessageBox(HWND_DESKTOP,"Unable to start program","",MB_OK);
            return 1;
         }
      CloseHandle(pif.hProcess);
      CloseHandle(pif.hThread);
      return 0;
    }
    
    Exec( "C:\\Dev-Cpp\\madness2.exe" );
    any ideas??

  7. #7
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Try putting the Exec("C:\\ ... line inside main()...
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #8
    Registered User
    Join Date
    Apr 2005
    Posts
    22
    cant believe i missed that lol.
    yep, that works now.
    thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  2. Making Program Launch Full Screen
    By mrtechguy in forum C++ Programming
    Replies: 19
    Last Post: 03-15-2006, 01:06 AM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 06:49 PM
  4. launch program from website
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 01-20-2002, 06:41 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21