Find windows folder programmatically in c#

Crash893 picture Crash893 · Sep 30, 2009 · Viewed 39.9k times · Source

I am writing a program to kill and restart explorer but I don't want to hard code the location because some people install windows in different places (for example I found someone who had it installed in the d:\ drive where the C:\ drive did exist but had nothing installed on it)

I tried looking under Environment.SpecialFolder. but I don't see a "windows" option under that

What is the best way to do this?

Answer

Omar picture Omar · Sep 30, 2009

http://msdn.microsoft.com/en-us/library/77zkk0b6.aspx

Try these:

Environment.GetEnvironmentVariable("SystemRoot")

Environment.GetEnvironmentVariable("windir")