[ACCEPTED]-How do you detect the main hard drive letter such as C: drive?-c#

Accepted answer
Score: 64

Try

Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System));

That will return (normally) C:\

But it 3 depends on how you define the "main" hard 2 drive. This will give you the drive Windows 1 is installed on.

Score: 22

This should work (assuming you want the 1 drive that windows is on):

string rootDrive = Path.GetPathRoot(Environment.SystemDirectory);
Score: 4
Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0,1)

Reference from here.

0

Score: 3

"SystemDrive" is the environment variable 1 on XP that you want.

Score: 2
var d = Directory.GetDirectoryRoot(Environment.GetEnvironmentVariable("windir"));

0

More Related questions