先上一段代码:
private void Form1_Load(object sender, EventArgs e)
{
OperatingSystem os = Environment.OSVersion;
switch (os.Platform)
{
case PlatformID.Win32Windows:
switch (os.Version.Minor)
{
case :
label1.Text = "Windows 95 ";
break;
case :
if (os.Version.Revision.ToString() == "2222A ")
label1.Text = "Windows 98 第二版 ";
else
label1.Text = "Windows 98 ";
break;
case :
label1.Text = "Windows Me ";
break;
}
break;
case PlatformID.Win32NT:
switch (os.Version.Major)
{
case :
label1.Text = "Windows NT 3.51 ";
break;
case :
label1.Text = "Windows NT 4.0 ";
break;
case :
switch (os.Version.Minor)
{
case :
label1.Text = "Windows 200 ";
break;
case :
label1.Text = "Windows XP ";
break;
case :
label1.Text = "Windows 2003 ";
break;
}
break;
case :
switch (os.Version.Minor)
{
case :
label1.Text = "Windows Vista ";
break;
case :
label1.Text = "Windows 7 ";
break;
}
break;
}
break;
}
}
这段代码很明显地揭示了Windows系列操作系统的版本编号。那么,使用一下批处理即可达到相同目的:
@echo off
ver|find "5.1"
if errorlevel 1 goto check7
if errorlevel 0 goto winxp
:winxp
echo windowsxp
rem 这行注释请改成命令z
goto end :check7
ver|find "6.1"
if errorlevel 1 goto other
if errorlevel 0 goto win7
:win7
echo win7
rem 这行注释请改成命令x
goto end :other
echo otherwindows
:end
pause
注:以上代码均来自于网络。