CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: running exe

  1. #1
    Join Date
    Feb 2001
    Posts
    14

    running exe

    I am wanting to run various different executable files when items are clicked in a list box control. How do I run an external exe file from within an application?

    Regards

    Tom


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: running exe

    You can use the Shell command

    ' start notepad
    Shell "c:\windows\notepad.exe"




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Sep 2001
    Posts
    512

    Re: running exe

    Shell is alright unless you want to know when the program has finished.

    You could try the following which will wait for the process to finish before continuing. Apologies for the source being in C++ but it should be easy to convert to VB.


    int CALLBACK ExecCmd(char cCmdLine[])
    {// Execute a command and wait for it to finish (Create a modal thread)
    //
    // Local variables
    //
    // si : Startup information
    // pi : Process information

    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    // Zero startupinfo structure
    ZeroMemory(&si, sizeof(STARTUPINFO));

    // Initialise startupinfo structure
    si.cb = sizeof(STARTUPINFO);
    si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USEPOSITION | STARTF_USESIZE;

    // Create process (i.e. run the required command)
    CreateProcess(NULL, cCmdLine, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);

    // Wait for process to end
    WaitForSingleObject(pi.hProcess, INFINITE);

    // Close process handle
    CloseHandle(pi.hProcess);
    return TRUE;
    }

    Hope this helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured