Although most of the time it's C:\WINDOWS\system32
, but sometimes it can be in D
partition or alike, how to get it programatically?
Asked
Active
Viewed 1.1k times
3 Answers
7
You can call the Windows API function SHGetFolderPath
and ask for CSIDL_SYSTEM
.
In Windows Vista and later, you can call SHGetKnownFolderPath
and ask for FOLDERID_System
. SHGetFolderPath
is just a wrapper around this function in later versions of Windows, but if you want your software to run on Windows XP, you'll need to use SHGetFolderPath
.

James McNellis
- 348,265
- 75
- 913
- 977
0
GetWindowsDirectory also is a possibility depending on the OS/purpose. Clearly SHGetFolderPath seems to be the MS recommended way

Chubsdad
- 24,777
- 4
- 73
- 129
-
2Actually, it would be GetSystemDirectory(). – MSalters Aug 23 '10 at 08:48