Run Program?

Pages: 12
How would I go about running a file like firefox or another program I created from a program i write? Is there code for this I can read about or someone can explain? Thank you!

~Mashed Pwntato
which platform you are talking about?
windows XP
you can use

1. CreateProcess
2. shellexecute

both will do.
Okay so I didn't have Shell32.lib or Shellapi.h Which folder should I put these in? Also, where can I get Shell32.lib?
Last edited on
Does anybody know? I'm completely stuck :/
Huh?
All compilers for Windows (except Cygwin, I think) include the WinAPI. You just need to #include <windows.h> and the compiler will do the rest. There's nothing to it.
Last edited on
It comes up with an error saying that it can't find <windows.h>
Compiler?
I'm using Dev-C++
Last edited on
That version includes windows.h, IIRC. Either I'm wrong and it doesn't, or your installation got screwed up. Try reinstalling it, or try using the compiler I sent you, which shouldn't give you any problems.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;


int main () 
{
system ("echo 'Hello World'");

return 0;
}



You could replace "echo 'Hello World'" with say firefox.

i.e.

system ("firefox");

Hope this helps.
Means that the program isn't portable though :(
The Windows API isn't really portable, however.
This is what I have gotten to now and it won't work! I've been trying to figure this out for forever and a half >:(
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <windows.h>
using namespace std;


int main() 
{
ShellExecute(hwnd,"open","Mozilla Firefox.exe",NULL,NULL,SW_SHOWNORMAL);
system("pause");
return 0;
}
Last edited on
Try this:
WinExec("programname.exe",SW_SHOW);
note that you must to enter full path to your program.
Okay, so this is what I tried:
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <windows.h>
using namespace std;


int main() 
{
WinExec("C:\Documents and Settings\Owner\Desktop\Mozilla Firefox.exe",SW_SHOW);
system("pause");
return 0;
}

It came up with [Warning] unknown escape sequence '/D'
[Warning] unknown escape sequence '/M'
[Linker error] undefined reference to '__cpu_features_init'
Id returned 1 exit status
'\' != '\\'

[Linker error] undefined reference to '__cpu_features_init'
Do you have two different installations of MinGW? That usually produces that linker error.
yeah, but I was still using Dev--c++. When I tried to install MinGW, I couldn't find the actual application to run. There doesn't seem to be a compiler or text editor or whatever there is supposed to be. I can't figure out how to use it...
The compilers are (of course) bin/g++.exe (C++) and bin/gcc.exe (C).
It's just the command line compiler. No IDE.
Pages: 12