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.
Asked
Active
Viewed 2,362 times
0
-
see http://stackoverflow.com/questions/194157/c-how-to-get-program-files-x86-on-vista-x64 for an example on Vista – Marijn May 26 '11 at 10:02
3 Answers
4
Use Environment.GetFolderPath(Environment.SpecialFolder.System);
, and for the program files folder use Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
.

Peter Mortensen
- 30,738
- 21
- 105
- 131

Leon Tayson
- 4,741
- 7
- 37
- 36
1
Have a look at this link. Environment.GetEnvironmentVariable
hopefully, would do the job for you.

Community
- 1
- 1

FIre Panda
- 6,537
- 2
- 25
- 38
1
string systemDrive = Path.GetRoot(Environment.GetFolderPath(Environment.SpecialFolder.System));
string progamFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);

Guillaume
- 12,824
- 3
- 40
- 48