| | |
program that starts another program.
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2008
Posts: 116
Reputation:
Solved Threads: 3
Is there a simple way to run another program, say IE, FF or just a simple .bat file sith c++? ive searched around a bit but all ive found is rocket science and didn't seem to be what im looking for. i dont wish to run it "trough" my program, just as if i had found the destination and doubleclick'ed it.
Yo god, where do i report a bug?
well, it's included in the windows.h, so try this:
EDIT: Negative. ShellExecute is NOT C++.... ShellExecute is a windows function that can be called from any language with the ability to use windows API's (C++ is such a language). This is windows specific, and won't work in *nix or Mac.... and is not a standard.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <windows.h> int main(int argc, char **argv) { ShellExecute(NULL, "open", "C:\\windows\\system32\\calc.exe","", "C:\\", SW_NORMAL); return 0; }
EDIT: Negative. ShellExecute is NOT C++.... ShellExecute is a windows function that can be called from any language with the ability to use windows API's (C++ is such a language). This is windows specific, and won't work in *nix or Mac.... and is not a standard.
Last edited by Comatose; Feb 13th, 2009 at 12:39 pm.
•
•
Join Date: Dec 2008
Posts: 116
Reputation:
Solved Threads: 3
Ahh thanks 
Now i tryed to look up the parameters (not that i couldn't find them, i just didn't understand ;-) )
Could you please explain the parameters you are using? just briefly, i hope its not too much trouble

Now i tryed to look up the parameters (not that i couldn't find them, i just didn't understand ;-) )
Could you please explain the parameters you are using? just briefly, i hope its not too much trouble
Last edited by Bladtman242; Feb 13th, 2009 at 1:00 pm.
Yo god, where do i report a bug?
The first parameter, hWnd (passed NULL) is the window to associate the new process with (NULL means you aren't using this feature).
The second, lpOperation, is what you want to do with the file specified in the next parameter. Here we are "open"ing it.
Speaking of which, the third is lpFile: the file you want to perform the operation on.
The fourth, lpParameters is a string of the arguments you want to pass into the new process. These are not used in this situation.
Next is lpDirectory. This is the path you want the new process to think it was started from.
Finally, we have nShowCommand: this just specifies the starting state of the window for the new process. SW_NORMAL specifies that, what do ya know, it should start in normal mode!
You can look at specifics including other possible arguments at msdn's documentation for this function.
The second, lpOperation, is what you want to do with the file specified in the next parameter. Here we are "open"ing it.
Speaking of which, the third is lpFile: the file you want to perform the operation on.
The fourth, lpParameters is a string of the arguments you want to pass into the new process. These are not used in this situation.
Next is lpDirectory. This is the path you want the new process to think it was started from.
Finally, we have nShowCommand: this just specifies the starting state of the window for the new process. SW_NORMAL specifies that, what do ya know, it should start in normal mode!
You can look at specifics including other possible arguments at msdn's documentation for this function.
Last edited by death_oclock; Feb 13th, 2009 at 10:34 pm.
•
•
Join Date: Dec 2008
Posts: 116
Reputation:
Solved Threads: 3
Thank you death_oclock, that was really helpfull
Cikara21, could you wxplain that?
Okay, Comatose: i tried it out, made a simple .bat called test.bat located on C:\, containing (rediculus i know)
and then a c++ "program":
Why does that not work? :/

Cikara21, could you wxplain that?

Okay, Comatose: i tried it out, made a simple .bat called test.bat located on C:\, containing
C++ Syntax (Toggle Plain Text)
msg * Hi %username% u rule
and then a c++ "program":
c++ Syntax (Toggle Plain Text)
#include <iostream> #include <windows.h> using namespace std; int main() { ShellExecute(NULL, "open", "C:\\test.bat","", "C:\\", SW_NORMAL); return 0; }
Why does that not work? :/
Yo god, where do i report a bug?
![]() |
Similar Threads
- how to execute an *.exe file in a c-program? (C)
- PLEASE HELP about Using C# to add an executable file to my program! (C#)
- Program Issues (C++)
- Only 1 instance of program (Java)
- Want help making program access a web page automatic. (C)
- Need a little help with a stack program. (C++)
- what is the effect of using constructors in the program? (Java)
- How to develop a new program (C++)
Other Threads in the C++ Forum
- Previous Thread: linked list help
- Next Thread: how i can to add for microsoft visual c++ mfc option
Views: 3373 | Replies: 65
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






