Open app in c++?

closed account (EAUX92yv)
I was wondering if I could open a third party application or file inside of a C++ program. I want to be able to type a phrase and open a program. Can someone help me? Thanks in advance!
You might be able to do this:
 
system("Directory/File.exe");
Your question is answered here http://www.cplusplus.com/forum/unices/2047/

In general, look at execv and related functions
closed account (EAUX92yv)
When I use system("Directory/File.exe"); and run the program, it never runs what I tell it to run. Can you please tell me how this works?
closed account (EAUX92yv)
That doesn't help me because I use Windows.
"Directory/File.exe" needs to contain the full drive+path+filename. Any '\' character needs to be doubled to '\\'.
If there are spaces in the path, you will need to enclose the entire command in quotes, remember to escape them with the '\' character too.
Last edited on
closed account (EAUX92yv)
Can you tell me what is wrong with my code?

else if (command1=="open c++")
{
system("C:\\ProgramData\\Microsoft\\Windows\\StartMenu\\Programs\\MicrosoftVisualSutdio2010Express.exe");
}

When I run it and command1==open c++ it just exits. Thanks for the help so far!
Is the exe really called MicrosoftVisualSutdio2010Express.exe?
I would have expected MicrosoftVisualStudio2010Express.exe.
closed account (EAUX92yv)
whoops...
closed account (EAUX92yv)
When I fixed the typo, nothing else changed. This is my code:
#include "targetver.h"
#include "stdafx.h"
#include "iostream"
#include "windows.h"
#include "string"
using namespace std;
string command1;
string command2;
string command3;
string command4;
string command5;
string command6;
string command7;
string command8;
string command9;
string command10;
string command11;
string command12;
string command13;
string command14;
string command15;
string command16;
string command17;
string command18;
string command19;
string command20;
string command21;
string command22;
string command23;
string command24;
string command25;
string command26;
string command27;
string command28;
string command29;
string command30;
string word1;
string word2;
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"Type your command.\n";
cin>>command1;
if (command1=="type")
{
cin>>word1;
cin>>word2;
}
else if (command1=="open c++")
{
system("C:\\Users\\Michael\\Desktop\\Microsoft\Visual\C++\2010\Express");
}
else if (command1=="open notepad++")
{
}
else if (command1=="open notepad")
{
}
else if (command1=="open word starter")
{
}
else if (command1=="open tv")
{
}
else if (command1=="open allmyapps")
{
}
else if (command1=="open spotify")
{
}
else if (command1=="open skype")
{
}
else if (command1=="open chrome")
{
}
else if (command1=="open wordpad")
{
}
else if (command1=="open evernote")
{
}
else if (command1=="open mineshafter")
{
}
else if (command1=="open left 4 dead")
{
}
else if (command1=="open left 4 dead 2")
{
}
else if (command1=="open paint")
{
}
else if (command1=="open steam")
{
}
else if (command1=="open excel starter")
{
}
else if (command1=="open avg")
{
}
else if (command1=="open avast")
{
}
else if (command1=="open darksiders")
{
}
else if (command1=="open sniper elite")
{
}
else if (command1=="open combat arms")
{
}
else if (command1=="open flight")
{
}
else if (command1=="open utorrent")
{
}
else if (command1=="open bearshare")
{
}
else if (command1=="open ezvid")
{
}
return 0;
}

What is wrong?
Hmm...

Tips:
-Try not to hard-code your programmes.
-Also, too much globals. I heard they can cause mem leaks.
Ok. What are these \Visual\C++\2010\Express? Must they have been escape codes or spaces?

What other errors are you getting if any?
Last edited on
closed account (EAUX92yv)
No errors appear. The program is(in its' current state), meant to take in a variable. If that variable is "type", it's supposed to take in random words. If that first variable is "open c++, then it's supposed to open Microsoft Visual C++ 2010 Express. What part of my code prevents this from occurring?
system("C:\\Users\\Michael\\Desktop\\Microsoft\Visual\C++\2010\Express");
shouldn't that be more like:
system("C:\\Users\\Michael\\Desktop\\Microsoft\\Visual\\C++\\2010\\Express");

and should there be a .exe on the end? I don't know the name of the executable.
closed account (EAUX92yv)
After using what Chervil said and adding .exe to the end, it still doesn't do as it should. Is what I'm trying impossible?
Ignoring the use of system() when there are better alternatives, I'm fairly sure the path is incorrect. My path and filename are "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\VCExpress.exe"
The files on your desktop are almost definitely NOT exe files, but rather lnk files, which is the (very much hidden) extension windows uses for shortcut files. You can tell visually if it's an lnk file by the little swooshing arrow at the bottom left inside the icon indicating that it is. The shortcut on your desktop, if you right click it and view its properties, actually points to a real exe file somewhere else. (Labeled as 'Target' in the properties page / Shortcut tab.) This is what you're more interested in.
Last edited on
Moeljbcp wrote:
The shortcut on your desktop, if you right click it and view its properties, actually points to a real exe file somewhere else.

Yes, exactly.

You can also right-click on items from the main "start" menu, and select "properties" to see what they are pointing to.
Last edited on
Topic archived. No new replies allowed.