【CSharp】判断当前操作系统帮助类
本文最后更新于 2024-05-07,文章可能存在过时内容,如有过时内容欢迎留言或者联系我进行反馈。
代码示例
public class OSHelper
{
// 获取操作系统ID
public static System.PlatformID GetPlatformID()
{
//获取系统信息
System.OperatingSystem osInfo = System.Environment.OSVersion;
//获取操作系统ID
System.PlatformID platformID = osInfo.Platform;
return platformID;
}
// 获取主版本号
public static int GetVersionMajor()
{
//获取系统信息
System.OperatingSystem osInfo = System.Environment.OSVersion;
//获取主版本号
int versionMajor = osInfo.Version.Major;
return versionMajor;
}
// 获取副版本号
public static int GetVersionMinor()
{
//获取系统信息
System.OperatingSystem osInfo = System.Environment.OSVersion;
//获取副版本号
int versionMinor = osInfo.Version.Minor;
return versionMinor;
}
//C#判断操作系统是否为Windows98
public static bool IsWindows98
{
get
{
return (Environment.OSVersion.Platform <span style="font-weight: bold;" class="mark"> PlatformID.Win32Windows) && (Environment.OSVersion.Version.Minor </span> 10) && (Environment.OSVersion.Version.Revision.ToString() != "2222A");
}
}
//C#判断操作系统是否为Windows98第二版
public static bool IsWindows98Second
{
get
{
return (Environment.OSVersion.Platform <span style="font-weight: bold;" class="mark"> PlatformID.Win32Windows) && (Environment.OSVersion.Version.Minor </span> 10) && (Environment.OSVersion.Version.Revision.ToString() <span style="font-weight: bold;" class="mark"> "2222A");
}
}
//C#判断操作系统是否为Windows2000
public static bool IsWindows2000
{
get
{
return (Environment.OSVersion.Platform </span> PlatformID.Win32NT) && (Environment.OSVersion.Version.Major <span style="font-weight: bold;" class="mark"> 5) && (Environment.OSVersion.Version.Minor </span> 0);
}
}
//C#判断操作系统是否为WindowsXP
public static bool IsWindowsXP
{
get
{
return (Environment.OSVersion.Platform <span style="font-weight: bold;" class="mark"> PlatformID.Win32NT) && (Environment.OSVersion.Version.Major </span> 5) && (Environment.OSVersion.Version.Minor <span style="font-weight: bold;" class="mark"> 1);
}
}
//C#判断操作系统是否为Windows2003
public static bool IsWindows2003
{
get
{
return (Environment.OSVersion.Platform </span> PlatformID.Win32NT) && (Environment.OSVersion.Version.Major <span style="font-weight: bold;" class="mark"> 5) && (Environment.OSVersion.Version.Minor </span> 2);
}
}
//C#判断操作系统是否为WindowsVista
public static bool IsWindowsVista
{
get
{
return (Environment.OSVersion.Platform <span style="font-weight: bold;" class="mark"> PlatformID.Win32NT) && (Environment.OSVersion.Version.Major </span> 6) && (Environment.OSVersion.Version.Minor <span style="font-weight: bold;" class="mark"> 0);
}
}
//C#判断操作系统是否为Windows7
public static bool IsWindows7
{
get
{
return (Environment.OSVersion.Platform </span> PlatformID.Win32NT) && (Environment.OSVersion.Version.Major <span style="font-weight: bold;" class="mark"> 6) && (Environment.OSVersion.Version.Minor </span> 1);
}
}
//C#判断操作系统是否为Unix
public static bool IsUnix
{
get
{
return Environment.OSVersion.Platform == PlatformID.Unix;
}
}
//利用C#判断当前操作系统是否为Win8系统
public static bool IsWindows8()
{
Version currentVersion = Environment.OSVersion.Version;
Version compareToVersion = new Version("6.2");
if (currentVersion.CompareTo(compareToVersion) >= 0)
return true;
else
return false;
}
}
- 感谢你赐予我前进的力量
赞赏者名单
因为你们的支持让我意识到写文章的价值🙏
评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果