access to system variables from C under W2K

Discussion in 'C Programming' started by Steve Adams, Jul 11, 2003.

  1. Steve Adams

    Steve Adams Guest

    Is there any way to access system variables from C under Windows 2000?
    I'd like to use the system variable %SystemRoot% in the remove(file)
    call:

    remove("%SystemRoot%\\System32\\drivers\\my_driver");

    Thanks for any ideas.

    Steve
     
    Steve Adams, Jul 11, 2003
    #1
    1. Advertising

  2. "George Huber" <> wrote in
    news:EIHPa.21216$:

    > "Steve Adams" <> wrote in message
    > news:...
    >> Is there any way to access system variables from C under Windows
    >> 2000? I'd like to use the system variable %SystemRoot% in the
    >> remove(file) call:
    >>
    >> remove("%SystemRoot%\\System32\\drivers\\my_driver");
    >>

    >
    > Try using:
    >
    > DWORD GetEnvironmentVariable(
    > LPCTSTR lpName, // environment variable name
    > LPTSTR lpBuffer, // buffer for variable value
    > DWORD nSize // size of buffer
    > );


    That is a platform specific API and has no place in comp.lang.c.

    > So to get the %SystemRoot% variable, the following code should work.
    >
    > char szPath[MAX_PATH]; // MAX_PATH is defined
    > in a windows header, 255 bytes.
    > DWORD dwRet;
    >
    > dwRet = GetEnvironmentVariable("SystemRoot", szPath, MAX_PATH);
    > if(dwRet == 0)
    > {
    > cout << "Variable SystemRoot not defined" << endl;
    > }


    and that is C++ which has no place here either. Also, please avoid top
    posting.

    As for the OP's question, AFAIK the mixed case environment variables in
    windows are a little special, and you'd be best served asking this
    question in one of the comp.os.ms-windows.programmer.* groups where
    people who know about this stuff can answer your question.

    Sinan.

    --
    A. Sinan Unur

    Remove dashes for address
    Spam bait: mailto:
     
    A. Sinan Unur, Jul 12, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Urs Vogel

    Setup problem under W2K

    Urs Vogel, Jun 3, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    340
    Urs Vogel
    Jun 3, 2004
  2. Thomas Heller
    Replies:
    6
    Views:
    745
    Claudio Grondi
    Apr 9, 2005
  3. Replies:
    1
    Views:
    435
    vincent wehren
    Jun 25, 2005
  4. Steve
    Replies:
    0
    Views:
    140
    Steve
    Jul 24, 2003
  5. barry

    Installing erb under W2K

    barry, Jul 13, 2004, in forum: Ruby
    Replies:
    3
    Views:
    137
    Randy Lawrence
    Jul 14, 2004
Loading...

Share This Page