c# 取操作系统信息
//操作系统PlatformID主版本号副版本号
public enum OsVer {
Windows95 = 140,
Windows98 = 1410,
WindowsMe = 1490,
WindowsNT35 = 230,
WindowsNT40 = 240,
Windows2000 = 250,
WindowsXP = 251,
Windows2003 = 252,
WindowsVista = 260,
Windows7 = 261,
Windows8 = 271
}
//判断
string iniPath = ystem.Environment.GetFolderPath(Environment.SpecialFolder.System);
//获取系统信息
System.OperatingSystem osInfo = System.Environment.OSVersion;
//获取操作系统ID
System.PlatformID platformID = osInfo.Platform;
//获取主版本号
int versionMajor = osInfo.Version.Major;
//获取副版本号
int versionMinor = osInfo.Version.Minor;
string osInfor = platformID.GetHashCode().ToString() + versionMajor.ToString() + versionMinor.ToString();
if (osInfor == OsVer.Windows7.GetHashCode().ToString())
{
iniPath = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
}
if (osInfor == OsVer.WindowsXP.GetHashCode().ToString())
{
iniPath = System.Environment.GetFolderPath(Environment.SpecialFolder.System);
}
return iniPath;
System.Environment.OSVersion.VersionString;用这句试试
仅供参考:
Version ver = System.Environment.OSVersion.Version;
string strClient = "";
if (ver.Major == 5 && ver.Minor == 1)
{
strClient = "Win XP";
}
else if (ver.Major == 6 && ver.Minor == 0)
{
strClient = "Win Vista";
}
else if (ver.Major == 6 && ver.Minor == 1)
{
strClient = "Win 7";
}
else if (ver.Major == 5 && ver.Minor == 0)
{
strClient = "Win 2000";
}
else
{
strClient = "未知";
}