Skip to content

获取Windows版本信息 - RegistryGetWindowsVersion

函数简介

获取Windows系统版本信息,返回包含版本详情的JSON对象。

接口名称

RegistryGetWindowsVersion

DLL调用

cpp
int64_t RegistryGetWindowsVersion(int64_t instance);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
std::string info = ola.RegistryGetWindowsVersion();
csharp
using OLAPlug;

var ola = new OLAPlugServer();
string info = ola.RegistryGetWindowsVersion();
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
info = ola.RegistryGetWindowsVersion()
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
ola.RegistryGetWindowsVersion();
cpp
var ola = com("OlaPlug.OlaSoft")
ola.RegistryGetWindowsVersion();
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.RegistryGetWindowsVersion();
text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.RegistryGetWindowsVersion();
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.RegistryGetWindowsVersion();
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.RegistryGetWindowsVersion();
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
ola.RegistryGetWindowsVersion();

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long ptr = RegistryGetWindowsVersion(instance);
if (ptr != 0) {
    char buffer[512] = {0};
    GetStringFromPtr(ptr, buffer, sizeof(buffer));
    FreeStringPtr(ptr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long RegistryGetWindowsVersion(long ola);

long instance = CreateCOLAPlugInterFace();
long ptr = RegistryGetWindowsVersion(instance);
if (ptr != 0) {
    StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
    GetStringFromPtr(ptr, sb, sb.Capacity);
    FreeStringPtr(ptr);
    string info = sb.ToString();
}
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ptr = ola.RegistryGetWindowsVersion(instance)

返回值

返回值说明
(返回值)长整数型。成功返回JSON对象字符串指针,失败返回 0。返回的字符串指针需调用 FreeStringPtr 释放内存。 返回的JSON对象包含以下字段: - productName:产品名称(如 "Windows 10 Pro") - currentVersion:主版本号(如 "10.0") - currentBuild:内部版本号(如 "19045") - releaseId:发布版本标识(如 "2009") - displayVersion:显示版本(如 "22H2") - buildBranch:构建分支 - ubr:Update Build Revision - installDate:安装日期(Unix时间戳) - registeredOwner:注册所有者 - registeredOrganization:注册组织(可选)。

注意事项

项目说明
版本信息从注册表 `HKEY_LOCAL_MAC版本信息从注册表 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion 读取。
部分字段在某些Windows版本中可能不存在部分字段在某些Windows版本中可能不存在。
Windows 11的 `currentBuilWindows 11的 currentBuild 为 22000 或更高。