C# operating system installed directory

拟墨画扇 提交于 2019-12-12 02:08:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!