How would I find the driver letter of the main hard disk on a Windows Operating system?
That is, the drive with Program Files
, System32
, and so on.
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.
Alternatively, use the Windows API call, SHGetSpecialFolderPath(), and pass in the correct CSIDL. Then you shouldn't have to rely on the environment variables.
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).