今天测试了WIN8, WIN8.1, WIN10 系统下GetVersionEx 函数,居然取出来的版本都是6.2 。 于是网上查找各种获取内核版本号的方法, 终于找到几种有用的方法, 记录下来以作备忘。
方法1: GetVersionEx, 该方法在WIN8.1以后无效 参看: https://msdn.microsoft.com/en-us/library/ms724451.aspx
procedure TForm1.Button1Click(Sender: TObject);
var
str : string;
ss : TStringStream;
buf: array[0..6] of byte;
OSVI : OSVERSIONINFO;
version : string;
begin
OSVI.dwOSversioninfoSize:=Sizeof(OSVERSIONINFO);
GetVersionEx(OSVI);
Edit4.Text := IntToStr(OSVI.dwMajorVersion) + ','
+IntToStr(OSVI.dwMinorVersion)+ ','
+IntToStr(OSVI.dwBuildNumber)+ ','
+IntToStr(OSVI.dwPlatformId)+ ',' +OSVI.szCSDVersion;
end;

方法2: 通过FWMIService查询系统表Win32_OperatingSystem, 该方法可以正常读取系统版本WIN8(6.2), WIN81(6.3), WIN10(10)

function GetWMIProperty(WMIType, WMIProperty: string): string;
const
WbemUser ='';
WbemPassword ='';
WbemComputer ='localhost';
var
FSWbemLocator, FWMIService, FWbemObjectSet, Obj: OleVariant;
C: Cardinal;
i,Len:integer;
tempItem:IEnumVariant;
count : integer;
msg : string;
begin
try
result := '';
FSWbemLocator:= CreateOleObject('WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
FWbemObjectSet := FWMIService.ExecQuery('Select * from Win32_' + WMIType);
tempItem := IEnumVariant(IUnknown(FWbemObjectSet._NewEnum));
Result:='';
count := 0;
while (tempItem.Next(1, obj, c) = S_OK) do
begin
Obj := Obj.Properties_.Item(WMIProperty, 0).Value;
if not VarIsNull(obj) then
begin
if(count > 0) then
result := result + ',';
Result := Result + trim(Obj);
Inc(count);
end;
end;
except
On E : Exception do
begin
msg := Format('GetWMIProperty Error,WMIType:%s, WMIProperty:%s, Msg:%s',
[WMIType, WMIProperty, E.ToString]);
ShowMessage(msg);
end;
end;
if(lowercase(result) = 'none') then
result := '';
end;
调用 : GetWMIProperty('OperatingSystem', 'Version');

方法3:通过ntdll.dll , NetServerGetInfo函数获取内核版本

program Project5;

{$APPTYPE CONSOLE}

uses
SysUtils, Windows;

type
NET_API_STATUS = DWORD;

_SERVER_INFO_101 = record
sv101_platform_id: DWORD;
sv101_name: LPWSTR;
sv101_version_major: DWORD;
sv101_version_minor: DWORD;
sv101_type: DWORD;
sv101_comment: LPWSTR;
end;
SERVER_INFO_101 = _SERVER_INFO_101;
PSERVER_INFO_101 = ^SERVER_INFO_101;
LPSERVER_INFO_101 = PSERVER_INFO_101;

const
MAJOR_VERSION_MASK = $0F;

function NetServerGetInfo(servername: LPWSTR; level: DWORD; var bufptr): NET_API_STATUS; stdcall; external 'Netapi32.dll';
function NetApiBufferFree(Buffer: Pointer): NET_API_STATUS; stdcall; external 'Netapi32.dll';

type
pfnRtlGetVersion = function(var RTL_OSVERSIONINFOEXW): LongInt; stdcall;
var
Buffer: PSERVER_INFO_101;
ver: RTL_OSVERSIONINFOEXW;
RtlGetVersion: pfnRtlGetVersion;
begin
Buffer := nil;
// Win32MajorVersion and Win32MinorVersion are populated from GetVersionEx()...
WriteLn(Format('GetVersionEx: %d.%d', [Win32MajorVersion, Win32MinorVersion])); // shows 6.2, as expected per GetVersionEx() documentation

@RtlGetVersion := GetProcAddress(GetModuleHandle('ntdll.dll'), 'RtlGetVersion');
if Assigned(RtlGetVersion) then
begin
ZeroMemory(@ver, SizeOf(ver));
ver.dwOSVersionInfoSize := SizeOf(ver);

if RtlGetVersion(ver) = 0 then
WriteLn(Format('RtlGetVersion: %d.%d', [ver.dwMajorVersion, ver.dwMinorVersion])); // shows 10.0
end;

if NetServerGetInfo(nil, 101, Buffer) = NO_ERROR then
try
WriteLn(Format('NetServerGetInfo: %d.%d', [Buffer.sv101_version_major and MAJOR_VERSION_MASK, Buffer.sv101_version_minor])); // shows 10.0
finally
NetApiBufferFree(Buffer);
end;
ReadLn;
end.

delphi 判断WIN8 , WIN8.1 , WIN10 系统版本的更多相关文章

  1. Windows系统版本判定那些事儿

    v:* { } o:* { } w:* { } .shape { }p.MsoNormal,li.MsoNormal,div.MsoNormal { margin: 0cm; margin-botto ...

  2. Windows系统版本判定那些事儿[转]

    Windows系统版本判定那些事儿 转自CSDN,原文链接,我比较不要脸, 全部给复制过来了 前言 本文并不是讨论Windows操作系统的版本来历和特点,也不是讨论为什么没有Win9,而是从程序员角度 ...

  3. Windows系统版本判定那些事儿(有图,各种情况,很清楚)

    前言 本文并不是讨论Windows操作系统的版本来历和特点,也不是讨论为什么没有Win9,而是从程序员角度讨论下Windows获取系统版本的方法和遇到的一些问题.在Win8和Win10出来之后,在获取 ...

  4. win10系统激活 快捷方式

    系统不定期就会提示激活,每次激活都是找各种工具折腾,今天捣鼓简单的脚本直接激活~~ 首先查看自己系统的版本,后面才能找到合适的激活码 win+R 启动程序 输入 winver 即可查看系统版本 2.查 ...

  5. windows如何获取Win10 Win8 Win8.1版本

    GetVersionEx 在win8 win8.1 win10 之后已经无法使用,如果非要使用的话需要让exe嵌入manifest,mainfest如下.这个文件需要已utf-8存储. <?xm ...

  6. XP,32/64位Win7,32/64位Win8,32/64位Win10系统 【春节版】

    本系统是10月5日最新完整版本的Windows10 安装版镜像,win10正式版,更新了重要补丁,提升应用加载速度,微软和百度今天宣布达成合作,百度成为win10 Edge浏览器中国默认主页和搜索引擎 ...

  7. 【春节版】年度精品 XP,32/64位Win7,32/64位Win8,32/64位Win10系统

    本系统是10月5日最新完整版本的Windows10 安装版镜像,win10正式版,更新了重要补丁,提升应用加载速度,微软和百度今天宣布达成合作,百度成为win10 Edge浏览器中国默认主页和搜索引擎 ...

  8. 【2016新年版】年度精品 XP,32/64位Win7,32/64位Win8,32/64位Win10系统

    本系统是10月5日最新完整版本的Windows10 安装版镜像,win10正式版,更新了重要补丁,提升应用加载速度,微软和百度今天宣布达成合作,百度成为win10 Edge浏览器中国默认主页和搜索引擎 ...

  9. 最新精品 强势来袭 XP,32/64位Win7,32/64位Win8,32/64位Win10系统【国庆版版】

    本系统是10月最新完整版本的Windows10 安装版镜像,Win10正式版,更新了重要补丁,提升应用加载速度,微软和百度今天宣布达成合作,百度成为Win10 Edge浏览器中国默认主页和搜索引擎,系 ...

随机推荐

  1. Delphi TextFile读取文本文件

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  2. vue工程本地代码请求http发生跨域提示错误解决方法

    这个可以使用代理进行跨域,这样看来跨域的方法就有几种了,对于iframe中的用postmassage,对于vue工程中的跨域则使用代理模式. 代理模式配置如下: 在config文件夹下找到index. ...

  3. bugku | login2(SKCTF) 200

    在响应包里面发现tips,base64解码后看到提示信息: $sql="SELECT username,password FROM admin WHERE username='". ...

  4. LintCode之各位相加

    题目描述: 我的代码 public class Solution { /* * @param num: a non-negative integer * @return: one digit */ p ...

  5. Union比or快 Using UNION is faster when it comes to cases like scan two different column。

    problem: 595. Big Countries A country is big if it has an area of bigger than 3 million square km or ...

  6. 103、Linux 编译 Kaldi 语音识别工具

    由于这个开源的语音识别工具Kaldi只能在Linux下面成功编译, 所以这一小节来写如何成功地在Linux下面编译Kaldi工具 (1)第一步,去github 上面把 Kaldi下载下来 git cl ...

  7. vue项目在IE下显示空白打不开问题

    近期遇到了项目是vue做的,在IE浏览器下打不开,显示空白问题,解决方案如下: 打不开的原因是因为少了babel-polyfill处理器,所以第一步需要下载: npm install babel-po ...

  8. s11 day106-107 RBAC模块

    一.登录 把权限存在session中 1. rbac models from django.db import models class Permission(models.Model): " ...

  9. POJ 1410 Intersection (计算几何)

    题目链接:POJ 1410 Description You are to write a program that has to decide whether a given line segment ...

  10. Windows开发,关于通过写代码加载PDB的那些事

    最近,接到一个活,要写一个程序,用来批量分析一堆dll和对应的PDB, 其实工作很简单,就是根据一堆偏移,通过PDB文件,找到对应dll里面对应位置的明文符号, 简单的需求,实现起来,通常都很麻烦, ...