CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Jul 2001
    Posts
    26

    Dynamically opening an external program

    Hello everyone,

    How would I dynamically open a program without knowing the path name?


  2. #2
    Join Date
    Feb 2001
    Location
    Sydney, Australia
    Posts
    1,909

    Re: Dynamically opening an external program

    Please, be more specific (some kind of example would be great)

    Please - rate answer if it helped you
    It gives me inspiration when I see myself in the top list =)

    Best regards,

    -----------
    Igor Soukhov (Brainbench/Tekmetrics ID:50759)
    [email protected] | ICQ:57404554 | http://soukhov.com

    Member of Russian Software Developer Network http://rsdn.ru
    Best regards,
    Igor Sukhov

    www.sukhov.net

  3. #3
    Join Date
    Jun 2001
    Posts
    126

    Re: Dynamically opening an external program

    use the function:
    WinExec("someapp.exe", SW_SHOW);
    if you dont specify a pathname it will search directories in a specific order. Check out WinExec in the index in MSDN.
    Hope this helps


  4. #4
    Join Date
    Feb 2001
    Location
    Sydney, Australia
    Posts
    1,909

    Re: Dynamically opening an external program

    yes (it's 'bout "confused even more") =)))
    anyway - you should provide a full path to you executableProgramm.exe if this executable not in:
    system catalogue, current catalogue, in path .... and use CreateProcess or ShellExecute to run a programm ...



    Please - rate answer if it helped you
    It gives me inspiration when I see myself in the top list =)

    Best regards,

    -----------
    Igor Soukhov (Brainbench/Tekmetrics ID:50759)
    [email protected] | ICQ:57404554 | http://soukhov.com

    Member of Russian Software Developer Network http://rsdn.ru
    Best regards,
    Igor Sukhov

    www.sukhov.net

  5. #5
    Join Date
    Jul 2001
    Posts
    26

    Converting DOS command line to Windows-based

    Hello everyone,

    I am trying to convert a command line that is in a DOS format into one that will run in Windows. It is still dynamically allocated, but in have parameters to pass in to the program call. The DOS command is as follows:

    SOME_EXECUTABLE MY_FILE -p SOME_PARAM -a ANOTHER_PARAM ...

    Any suggestions, clues, sites to look at?

    TIA


  6. #6
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    Re: Converting DOS command line to Windows-based

    system("SOME_EXECUTABLE MY_FILE -p SOME_PARAM -a ANOTHER_PARAM ...");

    I don't know if you need the ful path for the executable or not.


  7. #7
    Join Date
    Aug 2001
    Location
    WA, Bellevue, USA
    Posts
    86

    Re: Dynamically opening an external program

    SHELLEXECUTEINFO ShExecInfo;
    HINSTANCE hInst = NULL;
    ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask = NULL;
    ShExecInfo.hwnd = NULL;
    ShExecInfo.lpVerb = "Open";
    ShExecInfo.lpFile = Myprogram.exe; // with full path
    ShExecInfo.lpParameters = NULL;
    ShExecInfo.lpDirectory = NULL;
    ShExecInfo.nShow = SW_MAXIMIZE;
    ShExecInfo.hInstApp = NULL;

    ShellExecuteEx(&ShExecInfo);
    Best Regards
    Agha Shujaa Khan




  8. #8
    Join Date
    Jul 2001
    Posts
    26

    Re: Dynamically opening an external program

    What does that do?


  9. #9
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Converting DOS command line to Windows-based

    You don't need the full path as long as your application you want to start is within the search path which is set in your environment...

    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds

  10. #10
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Converting DOS command line to Windows-based


    STARTUPINFO StartupInfo;
    PROCESS_INFORMATION ProcessInfo;

    // Zero structures
    memset(&StartupInfo, 0, sizeof(StartupInfo));
    memset(&ProcessInfo, 0, sizeof(ProcessInfo));

    // Set structure size
    StartupInfo.cb = sizeof(StartupInfo);

    // Start other application
    CreateProcess("SOME_EXECUTABLE",
    "MY_FILE -p SOME_PARAM -a ANOTHER_PARAM",
    NULL,
    NULL,
    FALSE,
    CREATE_DEFAULT_ERROR_MODE,
    NULL,
    NULL,
    &StartupInfo,
    &ProcessInfo);




    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds

  11. #11
    Join Date
    Aug 2001
    Location
    WA, Bellevue, USA
    Posts
    86

    Re: Dynamically opening an external program

    SHELLEXECUTEINFO ShExecInfo;
    HINSTANCE hInst = NULL;
    ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask = NULL;
    ShExecInfo.hwnd = NULL;
    ShExecInfo.lpVerb = "Open";
    ShExecInfo.lpFile = Myprogram.exe; // with full path
    ShExecInfo.lpParameters = “MY_FILE -p SOME_PARAM -a ANOTHER_PARAM ...”;
    ShExecInfo.lpDirectory = NULL;
    ShExecInfo.nShow = SW_MAXIMIZE;
    ShExecInfo.hInstApp = NULL;

    ShellExecuteEx(&ShExecInfo);

    It is extremely simple thing to execute external programs with any number of parameters.



  12. #12
    Join Date
    Jul 2001
    Posts
    26

    Re: Dynamically opening an external program

    I am sorry if I have insulted your intelligence in any way, but I didn't understand the first post, which is why I asked what it did. Assuming this is an "extremely simple thing to execute," I would really appreciate some type of comment to explain this marvelous piece of code that you have provided for me. Thank you again for responding.


  13. #13
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Dynamically opening an external program

    Hi,

    His code is one way to start another application.

    SHELLEXECUTEINFO ShExecInfo;
    HINSTANCE hInst = NULL;

    ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); // Size of this structure in bytes
    ShExecInfo.fMask = NULL; // Array of flags that indicate the content and validity
    // of the other structure members
    ShExecInfo.hwnd = NULL; // Window handle to any message boxes that the system may
    // produce while executing this function
    ShExecInfo.lpVerb = "Open"; // Specifies an action for the application to perform
    ShExecInfo.lpFile = "c:\\notepad.exe"; // Application to be started (with complete path)
    ShExecInfo.lpParameters = "MY_FILE -p SOME_PARAM -a ANOTHER_PARAM"; // Specifies the command line arguments for the application
    // to be started
    ShExecInfo.lpDirectory = NULL; // Specifies the working directory for the application
    // to be started
    ShExecInfo.nShow = SW_MAXIMIZE; // Specifies how the application is to be shown when
    // it is opened
    ShExecInfo.hInstApp = hInst; // Receives a value greater than 32 if successful, or an error
    // value that is less than or equal to 32 otherwise



    There are some optional members of this structure (like process handle, icon handle, hot ke etc.) which you can also set before passing this structure to 'ShellExecuteEx()'. See MSDN (http://msdn.microsoft.com) for further information. Hope this helps.

    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds

  14. #14
    Join Date
    Aug 2001
    Location
    WA, Bellevue, USA
    Posts
    86

    Re: Dynamically opening an external program

    This is a console application (ExeToPad , I meant Executable to notepad), which I complied and tested and works ok. I demonstrated with this program that how you can open notepad with this program. As you might know that notepad accept line arguments, a file name which you like to open. You might not have that file, but notepad will accepts mytest.txt file name as argument and will give you an error message “can not find mytexr.txt file. Do you want to create that file?
    Here is the whole program.

    #include "stdafx.h"
    #include <windows.h>

    int main(int argc, char* argv[])
    {

    SHELLEXECUTEINFO ShExecInfo;
    HINSTANCE hInst = NULL;
    ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask = NULL;
    ShExecInfo.hwnd = NULL;
    ShExecInfo.lpVerb = NULL;
    ShExecInfo.lpFile = "notepad.exe";
    ShExecInfo.lpParameters = "mytext.txt";
    ShExecInfo.lpDirectory = NULL;
    ShExecInfo.nShow = SW_MAXIMIZE;
    ShExecInfo.hInstApp = NULL;
    ShellExecuteEx(&ShExecInfo);
    return 0;
    }



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