Reputation: 1087
I want to get system folder in windows, by reading SystemRoot. How can I do it? many thanks!
Upvotes: 0
Views: 726
Reputation: 13192
If you want to read the environment variables, use getenv or GetEnvironmentVariable.
However, if you want to find the %SYSTEMROOT%
directory consider using GetWindowsFolder
For other special folders, you can use SHGetKnownFolderPath or SHGetFolderPath
Upvotes: 3
Reputation: 34408
There's a windows API you should use instead: GetWindowsDirectory
But if you do want to read from the environment you can use GetEnvironmentVariable, or from the C runtime with getenv or even get the environment pointer from the unofficial third main argument int main(argc, argv, envp)
which is supported by the VC runtime.
Upvotes: 1
Reputation: 3120
This should be fairly easy with GetEnvironmentVariable():
DWORD WINAPI GetEnvironmentVariable(
__in_opt LPCTSTR lpName,
__out_opt LPTSTR lpBuffer,
__in DWORD nSize
);
See MSDN on GetEnvironmentVariable() for more infos and some examples (the function is used in Example 2)
Upvotes: 0