Recipe 20.7. Getting the Windows DirectoryProblemYou need to know the full path to the Windows directory. SolutionCall the GetWinDir method created for your use here to return the Windows directory path in a string: public static string GetWinDir() { string sysDir = Environment.GetFolderPath(Environment.SpecialFolder.System); return Path.GetFullPath(sysDir + @"\.."); } DiscussionThere is an enumeration to describe almost every significant operating system folder (Environment.SpecialFolder). But for some reason, since the inception of .NET, the Windows directory has been deemed unacceptably off-limits. This recipe exists for want of an Environment.SpecialFolder.Windows value. Another way to get at this value is to use the Environment.GetEnvironmentVariable function, passing in "windir" as the value. Table 20-3 shows all of the other places in the OS you can get through Environment.SpecialFolder.
See AlsoSee the "Environment.SpecialFolder Enumeration" and "Environment.GetFolderPath Method" topics in the MSDN documentation. |