如何获取系统盘符? [英] How can I get the system drive letter?
问题描述
如何在 Windows 操作系统上找到主硬盘的驱动程序号?
How would I find the driver letter of the main hard disk on a Windows Operating system?
即带有Program Files
、System32
等的驱动器.
推荐答案
有一个名为 SystemDrive
的环境变量被设置为系统驱动器(出人意料地足够).getenv()
调用是您获取它的方法.
There's an environment variable called SystemDrive
which is set to the system drive (surprisingly enough). The getenv()
call is how you can get to it.
char *sysDrive = getenv ("SystemDrive");
if (sysDrive == NULL) {
// vote me down.
} else {
// vote me up and use it.
}
此页面列出了大量可用的环境变量,如果您不能依赖特定的系统驱动器上存在的目录.
This page lists a whole slew of environment variables available if you can't rely on specific directories existing on the system drive.
或者,使用 Windows API 调用,SHGetSpecialFolderPath(),并传入正确的 CSIDL.那么你不应该依赖环境变量.
Alternatively, use the Windows API call, SHGetSpecialFolderPath(), and pass in the correct CSIDL. Then you shouldn't have to rely on the environment variables.
尽管在那些页面上注意这已被 Vista 中的其他函数取代(它应该仍然可以工作,因为此函数成为新函数的包装器).
Although take note on those pages that this has been superceded by other functions in Vista (it should still work since this function becomes a wrapper around the new one).
这篇关于如何获取系统盘符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!