Skip to main content
 首页 » 网络收集

vc++之汇编获取系统版本

2014年10月11日 00:49:4463200

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

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

 //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;
}

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


评论列表暂无评论
发表评论
新浪微博
微信