ShellExecute query

Posted on 2007-08-02
Last Modified: 2010-04-01

I'm looking for code to allow me to execute commands outside from my DLL. Just need to execute scripts and execuatbel etc.

I have been looking at the ShellExecute whcih seems suitable but could someone let me know if this is the best appraoch and if so, can you tell me how I use the GertLastError if it fails so I can print out the details.


Question by:oddbin
    LVL 45

    Expert Comment

    Hi oddbin,

    There are several ways to do this.

    -  If you're looking for a simple way to pause the program and run another, system() is probably the easiest.
    -  If you want to run another program and read it's output (or send data to it) check out popen().

    What are you trying to accomplish?

    Author Comment

    I just need to be able to execute a script of executable and pass them parameters.

    system is not recommended so i'd prefer not to use it. It would seem the ShellExecute is the way to go, i jst need help coding it.
    LVL 45

    Accepted Solution


    Ok.  Here's one call:

    ShellExecute (NULL, "open", "CommandName", "parameter1 parameter2 ... parametern", NULL, SW_NORMAL);

    P1 is the Window handle.  If the command doesn't need the window handle, pass NULL.
    "open" is the action.  You want to run (open) the file.
    CommandName is the object that you want to run (open).
    "Parameter1 ... ParameterN" is the parameter list as if the program were being run from the command line.  If you don't need parameters, pass NULL instead of "".
    If you want the program to run in a particular directory, the path goes in the 5th parameter.  NULL says use CWD.

    The last parameter controls how the window looks while the program runs.

    The API is documented here:

    Good Luck,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now