主题
获取已安装软件列表 - RegistryGetInstalledSoftware
函数简介
获取系统已安装软件列表,返回包含软件信息的JSON数组。
接口名称
RegistryGetInstalledSoftwareDLL调用
cpp
int64_t RegistryGetInstalledSoftware(int64_t instance);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
std::string list = ola.RegistryGetInstalledSoftware();csharp
using OLAPlug;
var ola = new OLAPlugServer();
string list = ola.RegistryGetInstalledSoftware();python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
software_list = ola.RegistryGetInstalledSoftware()java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
ola.RegistryGetInstalledSoftware();cpp
var ola = com("OlaPlug.OlaSoft")
ola.RegistryGetInstalledSoftware();vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.RegistryGetInstalledSoftware();text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.RegistryGetInstalledSoftware();aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.RegistryGetInstalledSoftware();text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.RegistryGetInstalledSoftware();cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
ola.RegistryGetInstalledSoftware();原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long ptr = RegistryGetInstalledSoftware(instance);
if (ptr != 0) {
char buffer[8192] = {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 RegistryGetInstalledSoftware(long ola);
long instance = CreateCOLAPlugInterFace();
long ptr = RegistryGetInstalledSoftware(instance);
if (ptr != 0) {
StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
GetStringFromPtr(ptr, sb, sb.Capacity);
FreeStringPtr(ptr);
string list = 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.RegistryGetInstalledSoftware(instance)返回值
| 返回值 | 说明 |
|---|---|
| (返回值) | 长整数型。成功返回JSON数组字符串指针,失败返回 0。返回的字符串指针需调用 FreeStringPtr 释放内存。 返回的JSON数组中每个软件对象包含以下字段: - name:软件名称 - version:版本号 - publisher:发行商 - installDate:安装日期(YYYYMMDD格式) - installLocation:安装位置(可选) - uninstallString:卸载命令(可选)。 |
注意事项
| 项目 | 说明 |
|---|---|
| 该函数会同时扫描32位和64位软件列表 | 该函数会同时扫描32位和64位软件列表。 |
| 扫描过程可能耗时较长 | 扫描过程可能耗时较长,建议在后台线程执行。 |
| 某些便携软件可能不会出现在列表中 | 某些便携软件可能不会出现在列表中。 |
| 部分字段可能为空 | 部分字段可能为空,取决于软件的安装信息完整性。 |
