我怎样才能获得系统驱动器号?

时间:2021-12-20 22:40:29

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

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

That is, the drive with Program Files, System32, and so on.

也就是说,带有Program Files,System32等的驱动器。

5 个解决方案

#1


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.

有一个名为SystemDrive的环境变量,它被设置为系统驱动器(令人惊讶的是足够)。 getenv()调用是你如何得到它。

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.

如果您不能依赖系统驱动器上存在的特定目录,此页面列出了一大堆可用的环境变量。

Alternatively, use the Windows API call, SHGetSpecialFolderPath(), and pass in the correct CSIDL. Then you shouldn't have to rely on the environment variables.

或者,使用Windows API调用SHGetSpecialFolderPath(),并传入正确的CSIDL。那么你不应该依赖环境变量。

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).

虽然请注意那些已经被Vista中的其他功能取代的页面(它应该仍然有效,因为这个功能成为新功能的包装器)。

#2


The API Call GetWindowsDirectory could be of assistance. You can further parse this information using API's to parse the drive letter information.

API调用GetWindowsDirectory可能会有所帮助。您可以使用API​​进一步解析此信息以解析驱动器号信息。

#3


SYSTEMDRIVE

PROGRAMFILES

SYSTEMROOT

WINDIR

Don't assume Program Files is on the same drive as Windows. It usually is. Usually.

不要假设Program Files与Windows在同一驱动器上。通常是。通常。

#4


Never use env variables like in the wrong answer above.
env variables are updatable by the user.

永远不要像上面的错误答案那样使用env变量。 env变量可由用户更新。

#5


See Getting System Information on MSDN. It explains how to get system information in depth for the most part. very informative.

请参阅在MSDN上获取系统信息。它解释了如何在大多数情况下深入获取系统信息。信息量很大。

#1


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.

有一个名为SystemDrive的环境变量,它被设置为系统驱动器(令人惊讶的是足够)。 getenv()调用是你如何得到它。

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.

如果您不能依赖系统驱动器上存在的特定目录,此页面列出了一大堆可用的环境变量。

Alternatively, use the Windows API call, SHGetSpecialFolderPath(), and pass in the correct CSIDL. Then you shouldn't have to rely on the environment variables.

或者,使用Windows API调用SHGetSpecialFolderPath(),并传入正确的CSIDL。那么你不应该依赖环境变量。

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).

虽然请注意那些已经被Vista中的其他功能取代的页面(它应该仍然有效,因为这个功能成为新功能的包装器)。

#2


The API Call GetWindowsDirectory could be of assistance. You can further parse this information using API's to parse the drive letter information.

API调用GetWindowsDirectory可能会有所帮助。您可以使用API​​进一步解析此信息以解析驱动器号信息。

#3


SYSTEMDRIVE

PROGRAMFILES

SYSTEMROOT

WINDIR

Don't assume Program Files is on the same drive as Windows. It usually is. Usually.

不要假设Program Files与Windows在同一驱动器上。通常是。通常。

#4


Never use env variables like in the wrong answer above.
env variables are updatable by the user.

永远不要像上面的错误答案那样使用env变量。 env变量可由用户更新。

#5


See Getting System Information on MSDN. It explains how to get system information in depth for the most part. very informative.

请参阅在MSDN上获取系统信息。它解释了如何在大多数情况下深入获取系统信息。信息量很大。