access to system variables from C under W2K

S

Steve Adams

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
 
A

A. Sinan Unur

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top