Get Windows directory

  • Thread starter Thread starter perspolis
  • Start date Start date
P

perspolis

Hi
How can I get name of Windows directory in c# without using API??
 
Claes said:
System.Environment.GetEnvironmentVariable("windir")

Or if you prefer WMI:

using (System.Management.ManagementClass mc = new
System.Management.ManagementClass("Win32_OperatingSystem"))
{
string windir = string.Empty;
ManagementObjectCollection.ManagementObjectEnumerator moen =
mc.GetInstances().GetEnumerator();
if (moen.MoveNext())
{
windir = moen.Current["WindowsDirectory"].ToString();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top