如何获取系统盘符? [英] How can I get the system drive letter?

查看:28
本文介绍了如何获取系统盘符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Windows 操作系统上找到主硬盘的驱动程序号?

How would I find the driver letter of the main hard disk on a Windows Operating system?

即带有Program FilesSystem32等的驱动器.

推荐答案

有一个名为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆