windows 如何使用C++获取system32目录的完整路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3544185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the full path to system32 directory with c++?
提问by wamp
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?
虽然大多数时候它是C:\WINDOWS\system32
,但有时它可以在D
分区或类似的地方,如何以编程方式获取它?
回答by James McNellis
You can call the Windows API function SHGetFolderPath
and ask for CSIDL_SYSTEM
.
您可以调用 Windows API 函数SHGetFolderPath
并请求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
.
在 Windows Vista 和更高版本中,您可以致电SHGetKnownFolderPath
并索要FOLDERID_System
. SHGetFolderPath
只是在更高版本的 Windows 中围绕此函数的包装器,但是如果您希望您的软件在 Windows XP 上运行,则需要使用SHGetFolderPath
.
回答by Furkat U.
回答by Chubsdad
GetWindowsDirectoryalso is a possibility depending on the OS/purpose. Clearly SHGetFolderPath seems to be the MS recommended way
根据操作系统/目的,GetWindowsDirectory也是一种可能性。显然 SHGetFolderPath 似乎是 MS 推荐的方式