在C#中怎么判断当前系统是XP还是WIN7?求代码!!!
展开全部
RegistryKey rk;
rk = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion");
string s = "当前操作系统版本:" + rk.GetValue("ProductName").ToString();
s = s + "\r\n" + rk.GetValue("CSDVersion").ToString();
s = s + "\r\n当前操作系统安装序列号:\r\n" + rk.GetValue("ProductId").ToString();
s = s + "\r\n当前系统版本号:" + rk.GetValue("CurrentBuildNumber").ToString();
rk.Close();
label1.Text = label1.Text + "\r\n" + s;
rk = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion");
string s = "当前操作系统版本:" + rk.GetValue("ProductName").ToString();
s = s + "\r\n" + rk.GetValue("CSDVersion").ToString();
s = s + "\r\n当前操作系统安装序列号:\r\n" + rk.GetValue("ProductId").ToString();
s = s + "\r\n当前系统版本号:" + rk.GetValue("CurrentBuildNumber").ToString();
rk.Close();
label1.Text = label1.Text + "\r\n" + s;
2013-04-16
展开全部
这是winform程序里的,试试: private void Form1_Load(object sender, EventArgs e)
{ OperatingSystem os = Environment.OSVersion;
switch (os.Platform)
{
case PlatformID.Win32Windows:
switch (os.Version.Minor)
{
case 0:
label1.Text = "Windows 95 ";
break;
case 10:
if (os.Version.Revision.ToString() == "2222A ")
label1.Text = "Windows 98 第二版 ";
else
label1.Text = "Windows 98 ";
break;
case 90:
label1.Text = "Windows Me ";
break;
}
break;
case PlatformID.Win32NT:
switch (os.Version.Major)
{
case 3:
label1.Text = "Windows NT 3.51 ";
break;
case 4:
label1.Text = "Windows NT 4.0 ";
break;
case 5:
switch (os.Version.Minor)
{
case 0:
label1.Text = "Windows 200 ";
break;
case 1:
label1.Text = "Windows XP ";
break;
case 2:
label1.Text = "Windows 2003 ";
break;
}
break;
case 6:
switch (os.Version.Minor)
{
case 0:
label1.Text = "Windows Vista ";
break;
case 1:
label1.Text = "Windows 7 ";
break;
}
break;
}
break;
} }
{ OperatingSystem os = Environment.OSVersion;
switch (os.Platform)
{
case PlatformID.Win32Windows:
switch (os.Version.Minor)
{
case 0:
label1.Text = "Windows 95 ";
break;
case 10:
if (os.Version.Revision.ToString() == "2222A ")
label1.Text = "Windows 98 第二版 ";
else
label1.Text = "Windows 98 ";
break;
case 90:
label1.Text = "Windows Me ";
break;
}
break;
case PlatformID.Win32NT:
switch (os.Version.Major)
{
case 3:
label1.Text = "Windows NT 3.51 ";
break;
case 4:
label1.Text = "Windows NT 4.0 ";
break;
case 5:
switch (os.Version.Minor)
{
case 0:
label1.Text = "Windows 200 ";
break;
case 1:
label1.Text = "Windows XP ";
break;
case 2:
label1.Text = "Windows 2003 ";
break;
}
break;
case 6:
switch (os.Version.Minor)
{
case 0:
label1.Text = "Windows Vista ";
break;
case 1:
label1.Text = "Windows 7 ";
break;
}
break;
}
break;
} }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不用这么麻烦,.net内部已经封装相应方法可以调用:
/// <summary>
/// 是否是win7系统
/// </summary>
public bool IsWin7System
{
get { return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major >= 6); }
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-04-16
展开全部
System.Console.WriteLine("当前系统为:{0}", System.Environment.OSVersion);结果
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-04-16
展开全部
System.Environment.OSVersion.Version
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询