VC获得window操作系统版本号, 获取操作系统位数
2015-06-23 16:20
387 查看
原文链接: http://www.greensoftcode.net/techntxt/2014315195331643021849
#include <Windows.h>
include <stdio.h>
#include <tchar.h>
#include <conio.h>
#include "stdafx.h"
#include "osVersion.h"
#include "osVersionDlg.h"
void getOsVersion(char* szOSName)
{
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
OSVERSIONINFO osvi;//定义OSVERSIONINFO数据结构对象
memset(&osvi, 0, sizeof(OSVERSIONINFO));//开空间
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);//定义大小
GetVersionEx (&osvi);//获得版本信息
dwMajorVersion=osvi.dwMajorVersion;//主版本号
dwMinorVersion=osvi.dwMinorVersion;//副版本
dwBuildNumber=osvi.dwBuildNumber;//创建号
dwPlatformId=osvi.dwPlatformId;//ID号
char swVersion[10]={0};
sprintf(swVersion,"%d.%d",dwMajorVersion,dwMinorVersion);
// dwVesion=atoi(swVersion);
if (!strcmp(swVersion,"4.0")) strcpy( szOSName,"win95"); //win95
if (!strcmp(swVersion,"4.1")) strcpy( szOSName,"win98"); //win98
if (!strcmp(swVersion,"4.9")) strcpy( szOSName,"win_me"); // win_me
if (!strcmp(swVersion,"3.51")) strcpy( szOSName,"win_Nt_3_5"); //win_Nt_3_5
if (!strcmp(swVersion,"5.0")) strcpy( szOSName,"win2000"); //win2000
if (!strcmp(swVersion,"5.1")) strcpy( szOSName,"win_xp"); //win_xp
if (!strcmp(swVersion,"5.2")) strcpy( szOSName,"win2003"); // win2003
if (!strcmp(swVersion,"6.6")) strcpy(szOSName,"vista"); //vista
if (!strcmp(swVersion,"6.1")) strcpy( szOSName,"win7"); // win7
if (!strcmp(swVersion,"6.1")) strcpy( szOSName,"win8"); // win8
}
#define __in
#define __out
#define MS_PROCESSOR_ARCHITECTURE_IA64 6
#define MS_PROCESSOR_ARCHITECTURE_AMD64 9
// 安全的取得真实系统信息
VOID SafeGetNativeSystemInfo(__out LPSYSTEM_INFO lpSystemInfo)
{
if (NULL==lpSystemInfo) return;
typedef VOID (WINAPI *LPFN_GetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo);
LPFN_GetNativeSystemInfo fnGetNativeSystemInfo = (LPFN_GetNativeSystemInfo)GetProcAddress( GetModuleHandle(_T("kernel32")), "GetNativeSystemInfo");;
if (NULL != fnGetNativeSystemInfo)
{
fnGetNativeSystemInfo(lpSystemInfo);
}
else
{
GetSystemInfo(lpSystemInfo);
}
}
// 获取操作系统位数
int GetSystemBits()
{
SYSTEM_INFO si;
SafeGetNativeSystemInfo(&si);
if (si.wProcessorArchitecture == MS_PROCESSOR_ARCHITECTURE_AMD64 ||
si.wProcessorArchitecture == MS_PROCESSOR_ARCHITECTURE_IA64 )
{
return 64;
}
return 32;
}
void COsVersionDlg::OnButton1()
{
// TODO: Add your control notification handler code here
char szOSVersion[40]={0};
getOsVersion(szOSVersion); //获得操作系统名称
int lzBit=GetSystemBits(); // 获取操作系统位数
}
#include <Windows.h>
include <stdio.h>
#include <tchar.h>
#include <conio.h>
#include "stdafx.h"
#include "osVersion.h"
#include "osVersionDlg.h"
void getOsVersion(char* szOSName)
{
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
OSVERSIONINFO osvi;//定义OSVERSIONINFO数据结构对象
memset(&osvi, 0, sizeof(OSVERSIONINFO));//开空间
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);//定义大小
GetVersionEx (&osvi);//获得版本信息
dwMajorVersion=osvi.dwMajorVersion;//主版本号
dwMinorVersion=osvi.dwMinorVersion;//副版本
dwBuildNumber=osvi.dwBuildNumber;//创建号
dwPlatformId=osvi.dwPlatformId;//ID号
char swVersion[10]={0};
sprintf(swVersion,"%d.%d",dwMajorVersion,dwMinorVersion);
// dwVesion=atoi(swVersion);
if (!strcmp(swVersion,"4.0")) strcpy( szOSName,"win95"); //win95
if (!strcmp(swVersion,"4.1")) strcpy( szOSName,"win98"); //win98
if (!strcmp(swVersion,"4.9")) strcpy( szOSName,"win_me"); // win_me
if (!strcmp(swVersion,"3.51")) strcpy( szOSName,"win_Nt_3_5"); //win_Nt_3_5
if (!strcmp(swVersion,"5.0")) strcpy( szOSName,"win2000"); //win2000
if (!strcmp(swVersion,"5.1")) strcpy( szOSName,"win_xp"); //win_xp
if (!strcmp(swVersion,"5.2")) strcpy( szOSName,"win2003"); // win2003
if (!strcmp(swVersion,"6.6")) strcpy(szOSName,"vista"); //vista
if (!strcmp(swVersion,"6.1")) strcpy( szOSName,"win7"); // win7
if (!strcmp(swVersion,"6.1")) strcpy( szOSName,"win8"); // win8
}
#define __in
#define __out
#define MS_PROCESSOR_ARCHITECTURE_IA64 6
#define MS_PROCESSOR_ARCHITECTURE_AMD64 9
// 安全的取得真实系统信息
VOID SafeGetNativeSystemInfo(__out LPSYSTEM_INFO lpSystemInfo)
{
if (NULL==lpSystemInfo) return;
typedef VOID (WINAPI *LPFN_GetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo);
LPFN_GetNativeSystemInfo fnGetNativeSystemInfo = (LPFN_GetNativeSystemInfo)GetProcAddress( GetModuleHandle(_T("kernel32")), "GetNativeSystemInfo");;
if (NULL != fnGetNativeSystemInfo)
{
fnGetNativeSystemInfo(lpSystemInfo);
}
else
{
GetSystemInfo(lpSystemInfo);
}
}
// 获取操作系统位数
int GetSystemBits()
{
SYSTEM_INFO si;
SafeGetNativeSystemInfo(&si);
if (si.wProcessorArchitecture == MS_PROCESSOR_ARCHITECTURE_AMD64 ||
si.wProcessorArchitecture == MS_PROCESSOR_ARCHITECTURE_IA64 )
{
return 64;
}
return 32;
}
void COsVersionDlg::OnButton1()
{
// TODO: Add your control notification handler code here
char szOSVersion[40]={0};
getOsVersion(szOSVersion); //获得操作系统名称
int lzBit=GetSystemBits(); // 获取操作系统位数
}
相关文章推荐
- IP地址在数据库里面的存储方式
- PhpStorm8.0.3配置Xdebug调试PHP程序
- java上传图片
- HADOOP 格式化 namenode节点 准备脚本
- Android BroadcastReceiver详细介绍
- 设置共享实验准备步骤
- ODPS技术架构及应用实践
- 游戏中的图像资源(位图与矢量图比较)
- Linux内存管理 Slab分配器
- Cocos2dx------A*寻路
- 躺赢:颠覆传统金融模式 理财就是这么简单
- gpload的简单实用
- Oracle 11g ORA-12514:TNS:监听程序当前无法识别连接描述符中请求的服务
- Docker Centos安装Mysql5.6
- DNS服务
- Linux——文件权限的查询与修改
- 《C程序员:从校园到职场》出版预告(3):从“阳春白雪”到“下里巴人”
- Segmentation fault 问题
- Centos6.5 源码搭建MYSQL5.5+MySQL主从复制
- Interpreting HANGANALYZE trace files to diagnose hanging and performance problems for 9i and 10g. (文