954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to execute an *.exe file in a c-program?

I am busy to make a program that starts with a menu, where
you can choose different options.
One of these options to execute a program.
for example :
download software in an flash-prom with loader.exe
loader idpartno.sr(where idpartno.sr is the code to be
downloaded.

Thanks for helping.

rookie-C
Newbie Poster
1 post since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

Use the shellExecute function. There's plenty of documentation on it in the MSDN. I copied this from a piece of one of my functions which wouldn't actually open notepad, it opens from a filename, in which case if it was a file with a *.txt extension it would open up the default application for that extension, in the case of .txt, Notepad. Hope this helps!

int iReturn = (int) ShellExecute(NULL, "open", "c:\\windows\\system32\\notepad.exe", NULL, NULL, SW_SHOWNORMAL);
// If ShellExecute returns an error code, let the user know.

if (iReturn <= 32)

{

MessageBox ("Cannot open file. File may have been moved or deleted.", "Error!", MB_OK | MB_ICONEXCLAMATION) ;

}

BlackDice
Light Poster
43 posts since Apr 2004
Reputation Points: 19
Solved Threads: 0
 

This should work:

#include
#include

int main()
{
(void)system("C:\\Windows\\System32\\notepad.exe");
return(0);
}

dil1788
Newbie Poster
1 post since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

This should work:

#include #include

int main() { (void)system("C:\\Windows\\System32\\notepad.exe"); return(0); }

Hi Dude,
This code is not working.
the system(); is compiled and returned a TRUE value. But couldn't get the output.

Try some other code.

vino4all
Newbie Poster
9 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

I am busy to make a program that starts with a menu, where you can choose different options. One of these options to execute a program. for example : download software in an flash-prom with loader.exe loader idpartno.sr(where idpartno.sr is the code to be downloaded.

Thanks for helping.

#include <stdlib.h>
#include<stdio.h>
#include<windows.h>

int main()
{

ShellExecute(NULL,"open","d:\\vlc.exe",NULL,NULL,SW_SHOWNORMAL);

return(0);
}

This works good fellas.

vino4all
Newbie Poster
9 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

please check the dates before posting. youre responding to someone who posted over two years ago, who was posting to someone else from four years prior to that.

nobody cares about this thread or is paying attention, all its doing now is cluttering forum space and wasting time.

jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You