program that starts another program.

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2008
Posts: 116
Reputation: Bladtman242 is an unknown quantity at this point 
Solved Threads: 3
Bladtman242 Bladtman242 is offline Offline
Junior Poster

program that starts another program.

 
0
  #1
Feb 13th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: program that starts another program.

 
0
  #2
Feb 13th, 2009
in windows can you use ShellExecute, which is an API call that will allow you to spawn an application.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 116
Reputation: Bladtman242 is an unknown quantity at this point 
Solved Threads: 3
Bladtman242 Bladtman242 is offline Offline
Junior Poster

Re: program that starts another program.

 
0
  #3
Feb 13th, 2009
Thanks for the quick answer
Is shellexecute a astandard function? like shellexecute(); or?

EDIT: perhaps i misunderstood, does ShellExecute have anything to do with the c++ language?
Last edited by Bladtman242; Feb 13th, 2009 at 12:33 pm.
Yo god, where do i report a bug?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: program that starts another program.

 
0
  #4
Feb 13th, 2009
well, it's included in the windows.h, so try this:
  1. #include <iostream>
  2. #include <windows.h>
  3. int main(int argc, char **argv)
  4. {
  5. ShellExecute(NULL, "open", "C:\\windows\\system32\\calc.exe","", "C:\\", SW_NORMAL);
  6. return 0;
  7. }

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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 116
Reputation: Bladtman242 is an unknown quantity at this point 
Solved Threads: 3
Bladtman242 Bladtman242 is offline Offline
Junior Poster

Re: program that starts another program.

 
0
  #5
Feb 13th, 2009
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
Last edited by Bladtman242; Feb 13th, 2009 at 1:00 pm.
Yo god, where do i report a bug?
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 357
Reputation: death_oclock will become famous soon enough death_oclock will become famous soon enough 
Solved Threads: 37
death_oclock's Avatar
death_oclock death_oclock is offline Offline
Posting Whiz

Re: program that starts another program.

 
1
  #6
Feb 13th, 2009
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.
Last edited by death_oclock; Feb 13th, 2009 at 10:34 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 338
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 66
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: program that starts another program.

 
0
  #7
Feb 14th, 2009
Or use.. execlp(...)
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: program that starts another program.

 
0
  #8
Feb 14th, 2009
Originally Posted by cikara21 View Post
Or use.. execlp(...)
Which I believe is *nix only.....
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 116
Reputation: Bladtman242 is an unknown quantity at this point 
Solved Threads: 3
Bladtman242 Bladtman242 is offline Offline
Junior Poster

Re: program that starts another program.

 
0
  #9
Feb 14th, 2009
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
  1. msg * Hi %username% u rule
(rediculus i know)
and then a c++ "program":
  1. #include <iostream>
  2. #include <windows.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. ShellExecute(NULL, "open", "C:\\test.bat","", "C:\\", SW_NORMAL);
  9. return 0;
  10. }

Why does that not work? :/
Yo god, where do i report a bug?
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 116
Reputation: Bladtman242 is an unknown quantity at this point 
Solved Threads: 3
Bladtman242 Bladtman242 is offline Offline
Junior Poster

Re: program that starts another program.

 
0
  #10
Feb 14th, 2009
Originally Posted by Bladtman242 View Post
Cikara21, could you wxplain that?
Originally Posted by Comatose
Which I believe is *nix only.....
^^ Okay. beaten by seconds by Comatose

So, does anyone know what i am doing wrong here?
Last edited by Bladtman242; Feb 14th, 2009 at 8:39 am.
Yo god, where do i report a bug?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 3373 | Replies: 65
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC