[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ShellExecute query

Posted on 2007-08-02
3
Medium Priority
?
244 Views
Last Modified: 2010-04-01
Hi,

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.

Thanks

0
Comment
Question by:oddbin
  • 2
3 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 19616907
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?
Kent
0
 

Author Comment

by:oddbin
ID: 19616981
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.
0
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 150 total points
ID: 19617161

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:  http://msdn2.microsoft.com/en-us/library/ms647732.aspx


Good Luck,
Kent
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

834 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