Pathing issue

So half of this works. When I type paint, it opens paint. I'm trying to get google chrome to open. I'm thinking I have the pathing wrong some how? I coppied it from its properties so it should be right. Anyone know why it's saying it can't find it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <iostream>
#include <string>
#include <windows.h>

using namespace std;
string program;

int main()
{
    cout << "What program would you like to open?" << endl;
    cin >> program;
    Sleep(3000);
    if (program == "paint")
        {
        system("start /max C:/Windows/System32/mspaint.exe");
    }
    if (program == "internet")
        {
        system("start /max C:\Program Files (x86)\Google\Chrome\Application\chrome.exe");
    }
}
Windows (and mostly everything else) requires you to put quotation marks (") between file paths that have spaces in them.

Without quotations, it treats the file path as two separate command arguments.

Further more, your code is probably getting warnings because you're using unescaped backslashes. Change the backslashes to forward slashes, or escape them ('\\').

 
        system("start /max \"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe\"");


EDIT: If you do it this way, it might not run correctly because... Windows®....

You have to "fake" a window title like this (first arg is empty string):
system("start \"\" /max \"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe\"");

In cmd, that would translate to start "" /max "C:/file path/with spaces.exe"
Last edited on
Hello Irhcsa,

Ganado makes good points. This is what I did to get it to work for me:

system("start /max C:\\\"Program Files (x86)\"\\Google\\Chrome\\Application\\chrome.exe");

When I tried Ganado's example of the \" before the C and \" after .exe it did not work for me. The part about putting "" around anything that has a space in it is good advice.

Hope this helps,

Andy
Thanks guys!
Topic archived. No new replies allowed.