获得Windows目录位置 C#

来源:百度知道 编辑:UC知道 时间:2024/09/28 14:37:10
System::Enviroument::SpecialFolder 里提供了很多特殊目录定义
没有找到Windows目录阿,怎么办呢?

没有WINDOWS目录.
你先用Environment.SpecialFolder.System获取"System"的目录.

然后在截取掉System字符串就是WINDOWS目录了.

以下代码:

string str = Environment.GetFolderPath(Environment.SpecialFolder.System);
string newStr = System.IO.Path.GetDirectoryName(str);

newStr就是WINDOWS目录了.

好了,给分吧.

using System;
using System.Configuration;
using System.Runtime.InteropServices;
using System.Management;
using System.Text;

/**//// <summary>
/// SystemInfo 的摘要说明
/// </summary>
public class SystemInfo
...{
private const int CHAR_COUNT = 128;
public SystemInfo()
...{

}
[DllImport("kernel32")]
private static extern void GetWindowsDirectory(StringBuilder WinDir, int count);
}