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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:05:23  来源:igfitidea点击:

How to get the full path to system32 directory with c++?

c++windows

提问by wamp

Although most of the time it's C:\WINDOWS\system32, but sometimes it can be in Dpartition or alike, how to get it programatically?

虽然大多数时候它是C:\WINDOWS\system32,但有时它可以在D分区或类似的地方,如何以编程方式获取它?

回答by James McNellis

You can call the Windows API function SHGetFolderPathand ask for CSIDL_SYSTEM.

您可以调用 Windows API 函数SHGetFolderPath并请求CSIDL_SYSTEM.

In Windows Vista and later, you can call SHGetKnownFolderPathand ask for FOLDERID_System. SHGetFolderPathis 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.

UINT WINAPI GetSystemDirectory(
  _Out_  LPTSTR lpBuffer,
  _In_   UINT uSize
);

You can use this as stated here

您可以按照此处所述使用它

回答by Chubsdad

GetWindowsDirectoryalso is a possibility depending on the OS/purpose. Clearly SHGetFolderPath seems to be the MS recommended way

根据操作系统/目的,GetWindowsDirectory也是一种可能性。显然 SHGetFolderPath 似乎是 MS 推荐的方式