How can I add %ProgramFiles% to a system() call?

Panarchy's Avatar, Join Date: Nov 2007
Contributor
Hello

How can I add %ProgramFiles% to a system() call?

Here is my current code (using Dev-C++);

Code:
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    system("diskmgmt.msc");
    system(""%ProgramFiles%"\\Symantec\\LiveUpdate\\LUALL.exe");
    system("PAUSE");
    return EXIT_SUCCESS;
}
Please tell me how to get this line: system(""%ProgramFiles%"\\Symantec\\LiveUpdate\\LU ALL.exe"); to work.

Thanks in advance,

Panarchy

PS: Once I've gotten this to work, I'd also like to know how to stop the command prompt window from appearing.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Looks from your other post like you've already sussed it but as with the backslash you also have to escape quotes to include them in a string.

You want system to execute the following:
Code:
"%ProgramFiles%\Symantec\LiveUpdate\LUALL.exe"
So the code to do this is:
Code:
system("\"%ProgramFiles%\\Symantec\\LiveUpdate\\LUALL.exe\"");
Panarchy's Avatar, Join Date: Nov 2007
Contributor
Thanks