A: 

Call getenv("%ProgramFiles%") and getenv("%WinDir%")

Sameer
I would not be dependent on environment variables.
Daniel A. White
Never trust Enivronment Variables. As they are accessible to user. He might change it.
claws
+1  A: 

Using Win32 API>

For the Windows folder:

TCHAR windir[NUM];
GetWindowsDirectory(windir, NUM);

For program files:

TCHAR pf[NUM];
SHGetSpecialFolderPath(
    0,
    pf, 
    CSIDL_PROGRAM_FILES, 
    FALSE ); 

Where NUM is the "maximum" size you guesstimate the length of the path is.

Also, note that SHGetSpecialFolderPath can be used to retrieve other "special" folder including the Windows folder just by replacing the third parameter to any from this list.

Anzurio
Many thanks! anzurio:)
sxingfeng
A: 

Most of these come from SHGetFolderPath, but GetSystemDirectory() returns the absolute location of C:\Windows\System32. Don't use GetWindowsDirectory(). It doesn't do what you want anymore.

Joshua