原文链接: 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(); // 获取操作系统位数

}

VC获得window操作系统版本号, 获取操作系统位数的更多相关文章

  1. python开发_platform_获取操作系统详细信息工具

    ''' python中,platform模块给我们提供了很多方法去获取操作系统的信息 如: import platform platform.platform() #获取操作系统名称及版本号,'Win ...

  2. NTDLL未文档化函数RtlGetNtVersionNumbers获取操作系统版本

    作为新手,对获取操作系统版本号好奇过,因为曾经假象过一个场景:自己的程序在windows xp环境下编译,在windows 2003, windows 7,windows 8是否需要提权或者兼容处理, ...

  3. 获取操作系统版本Asp.Net

    /// <summary> /// 获取操作系统版本号 /// </summary> /// <returns></returns> public st ...

  4. 批量ssh登录,获取操作系统、CPU、内存、硬盘信息<shell>

    说明:该脚本读取machine.txt文件中的机器名,然后批量ssh登录,获取每台机器的操作系统,CPU,内存,硬盘等信息. 使用方法:将文件保存为sh,chmod +x filename 为该sh文 ...

  5. Js获取操作系统版本 && 获得浏览器版本

    //利用原生Js获取操作系统版本function getOS() { var sUserAgent = navigator.userAgent; var isWin = (navigator.plat ...

  6. C# 获取操作系统相关信息

    1.获取操作系统版本(PC,PDA均支持) Environment.OSVersion 2.获取应用程序当前目录(PC支持) Environment.CurrentDirectory 3.列举本地硬盘 ...

  7. 根据UserAgent 获取操作系统名称

    /// <summary>        /// 根据 User Agent 获取操作系统名称        /// </summary>        private sta ...

  8. .NET Core 获取操作系统各种信息

    .NET Core 获取操作系统各种信息 一.前言 .NET Core 内置了一些API供我们获取操作系统.运行时.框架等信息.这些API不是很常用,所有有些小伙伴可能还不知道,这里做一些可能用到的获 ...

  9. C# 获取操作系统相关的信息

    本文通过一个Demo,讲解如何通过C#获取操作系统相关的信息,如内存大小,CPU大小,机器名,环境变量等操作系统软件.硬件相关信息,仅供学习分享使用,如有不足之处,还请指正. 涉及知识点: Envir ...

随机推荐

  1. Spring boot基础:配置文件配置变量、多环境的配置

    一.配置 resources下面application.properties 1.普通配置 resources下面application.properties,比如写上:server.port=909 ...

  2. GO语言基础之reflect反射

    反射reflection 1. 反射可以大大的提高程序的灵活性,使得 interface{} 有更大的发挥余地 2. 反射使用 TypeOf 和 ValueOf 函数从接口中获取目标对象信息 3. 反 ...

  3. rsync同步数据---把左边的文件全部拷贝到右边

    背景,配置好了ssh 使用rsa pulbic key的方式登陆远程服务器.//ssh-keygen -t rsa -b 2048 -f andy-rsync-key -P '' https://he ...

  4. CF 557B(Pasha and Tea-贪心)

    B. Pasha and Tea time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  5. (笔试题)删除K位数字

    题目: 现有一个 n 位数,你需要删除其中的 k 位,请问如何删除才能使得剩下的数最大? 比如当数为 2319274, k=1 时,删去 2 变成 319274 后是可能的最大值. 思路: 1.贪心算 ...

  6. (笔试题)小米Git

    题目: git是一种分布式代码管理工具,git通过树的形式记录文件的更改历史,比如: base'<--base<--A<--A' ^ | --- B<--B' 小米工程师常常需 ...

  7. 整数划分问题--DFS

    单点时限:1000ms 内存限制:256MB 描写叙述 Given two positive integers N and M, please divide N into several intege ...

  8. mac 下vim 配置文件

    " Configuration file for vim set modelines=0 " CVE-2007-2438 " Normally we use vim-ex ...

  9. 微信小程序 - 调用腾讯地图插件

    1. 登录公众号平台 https://mp.weixin.qq.com/ 2. 设置->第三方服务->添加插件->输入插件名称->申请 3. 项目中使用 3.1 app.jso ...

  10. python3安装Beautiful Soup爬虫组件

    第一步:下载beautifulsoup4-4.3.2.tar.gz 第二步:拷贝解压缩目录到C:\Python34\beautifulsoup4-4.3.2 第三步: 第四步: 第五步:拷贝C:\Py ...