2009-02-26 11 views

risposta

43

Prova

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

che restituirà (normalmente) C: \

Ma dipende da come si definisce il disco rigido "principale". Questo ti darà l'unità su cui è installato Windows.

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

Environment.GetFolderPath (Environment.SpecialFolder.System) .Substring (0,1)

rubato da here.

1

"SystemDrive" è la variabile di ambiente su XP che si desidera.

11

Questo dovrebbe funzionare (supponendo che si desidera l'unità che Windows è acceso):

string rootDrive = Path.GetPathRoot(Environment.SystemDirectory); 
Problemi correlati