问题
How do I find the drive, using C#, in which I installed the operating system (say, Windows 7)? Then I have to get the Program Files directory.
回答1:
Use Environment.GetFolderPath(Environment.SpecialFolder.System);
, and for the program files folder use Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
.
回答2:
Have a look at this link. Environment.GetEnvironmentVariable
hopefully, would do the job for you.
回答3:
string systemDrive = Path.GetRoot(Environment.GetFolderPath(Environment.SpecialFolder.System));
string progamFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
来源:https://stackoverflow.com/questions/6136763/c-sharp-operating-system-installed-directory