利用汇编代码获取系统版本,此功能也常常应用在各种软件上,应用非常广。

可将此代码封装成自己专用的类,方面使用。

 //CString GetOSVersionInfo() //这里直接返回字符串
int GetOSVersionInfo()       //这里返回对应的数值
//1:win2000 2:winxp 3:win2003 4:winvista 5:win7
{
 int a=0,b=0,i=0,j=0;
 _asm
 {
  pushad
   mov ebx,fs:[0x18] ; get self pointer from TEB
   mov eax,fs:[0x30] ; get pointer to PEB / database
   mov ebx,[eax+0A8h] ; get OSMinorVersion
   mov eax,[eax+0A4h] ; get OSMajorVersion
   mov j,ebx
   mov i,eax
   popad
 }
 if((i==5)&&(j==0))
 {
  //return "系统版本为 Windows 2000";
  return 1;
 }
 else if((i==5)&&(j==1))
 {  
  //return "系统版本为 Windows Xp";
  return 2;
 }
 else if((i==5)&&(j==2))
 {
  //return "系统版本为 Windows 2003";
  return 3;
 }
 else if((i==6)&&(j==0))
 {
  //return "系统版本为 Windows Vista";
  return 4;
 }
 else if((i==6)&&(j==1))
 {
  //return "系统版本为 Windows 7";
  return 5;
 }
}
//以上是两种方式
//下面代码 则是判断
//可以在按钮或其他地方做个判断
int my_version;
my_version=GetOSVersionInfo();
switch(my_version)
{
case 0:
MessageBox("未知系统");
break;
case 1:
MessageBox("win2000");
break;
case 2:
MessageBox("winxp");
break;
case 3:
MessageBox("win2003");
break;
case 4:
MessageBox("win vista");
break;
case 5:
MessageBox("win7");
break;
}

本代码非原创,收集来自网络。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。