Open the System Information file. In the System Information window, click the + symbol next to Components. Click the + next to Storage and click Drives. In the right-side of the window, you see information about the hard drive including its capacity and serial number.
You can open File Explorer by pressing Windows key + E . In the left pane, select This PC, and all drives are shown on the right. The screenshot shows a typical view of This PC, with three mounted drives.
On computers running Windows or MS-DOS, the hard drive is labeled with the C: drive letter. The reason is because it is the first available drive letter for hard drives.
Try
Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System));
That will return (normally) C:\
But it depends on how you define the "main" hard drive. This will give you the drive Windows is installed on.
This should work (assuming you want the drive that windows is on):
string rootDrive = Path.GetPathRoot(Environment.SystemDirectory);
"SystemDrive" is the environment variable on XP that you want.
Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0,1)
Reference from here.
var d = Directory.GetDirectoryRoot(Environment.GetEnvironmentVariable("windir"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With