//声明API
/// <summary>
/// 获取系统的System32目录
/// </summary>
/// <param name="lpBuffer"></param>
/// <param name="nSize"></param>
/// <returns></returns>
[DllImport("kernel32", EntryPoint = "GetSystemDirectoryA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern long GetSystemDirectory(StringBuilder lpBuffer, long nSize);
/// <summary>
/// 获取系统的Windows目录
/// </summary>
/// <param name="lpBuffer"></param>
/// <param name="nSize"></param>
/// <returns></returns>
[DllImport("kernel32", EntryPoint = "GetWindowsDirectoryA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern long GetWindowsDirectory(StringBuilder lpBuffer, long nSize);
//调用
public string GetSystemPath()
{
StringBuilder p = new StringBuilder(100);
long length;
length = GetSystemDirectory(p, 100);
return p.ToString();
}
public string GetWindowsPath()
{
StringBuilder p = new StringBuilder(100);
long length;
length = GetWindowsDirectory(p, 100);
return p.ToString();
}