1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'C' started by Panarchy, Apr 21, 2009.

  1. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    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\\LUALL.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.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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\"");
    
     
  3. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0

Share This Page