Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Executing a C Executable from Another C program

  • 21-03-2005 11:43AM
    #1
    Closed Accounts Posts: 1,541 ✭✭✭


    Hello All,

    I am looking for help on executing a C executable from within another C program.

    Basically I want to execute an executable on the sly without the user really knowing that another C program is actually executing.

    Is this possible?

    Thanks for any help.

    Finn :)


Comments

  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    No doubt some call like exec() (I don't know any C) will do the job for you?


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus




  • Closed Accounts Posts: 447 ✭✭MickFarr


    You can using the CreateProcess function I showed you in your other post.

    add these 2 lines
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_HIDE;

    For testing swap SW_HIDE with SW_NORMAL
    DWORD ExitCode;
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    
    
    memset(&si, 0, sizeof(si));
    memset(&pi, 0, sizeof(pi));
    si.cb = sizeof(si);
    si.dwFlags      =   STARTF_USESHOWWINDOW;
    si.wShowWindow  =   SW_HIDE;
    
    // Create the process. 
    if(!CreateProcess(NULL, "C:\\Program Files\\Internet Explorer\\iexplore.exe www.boards.ie",NULL,NULL,FALSE,CREATE_NO_WINDOW,NULL,NULL,&si,&pi))
       AfxMessageBox("CreateProcess failed.");
    
    // Close process. 
    GetExitCodeProcess(pi.hProcess, &ExitCode);
    TerminateProcess(pi.hProcess, ExitCode);
    


  • Closed Accounts Posts: 447 ✭✭MickFarr


    I hope your doing something naughty! :D


  • Registered Users, Registered Users 2 Posts: 4,003 ✭✭✭rsynnott


    finnpark wrote:
    Hello All,

    I am looking for help on executing a C executable from within another C program.

    Basically I want to execute an executable on the sly without the user really knowing that another C program is actually executing.

    Is this possible?

    Thanks for any help.

    Finn :)

    exec or system. Exec's probably handier if you want to provide arguments.


  • Advertisement
  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    Thanks All,

    Your help appreciated. All solutions suggested here work. In the end I am using system("name.exe"); as it is the handiest.

    Thanks again and yes I am am being very naughty. :D


Advertisement