Skip to content

检查是否以管理员权限运行 - IsElevated

函数简介

检测当前加载 OLAPlug 的进程是否已具备 Windows **管理员提升(UAC Elevated)**权限。

通过查询当前进程访问令牌的 TokenElevation 判断,等价于任务管理器中进程是否带有「已提升」状态。常用于绑定窗口、Hook、驱动相关能力调用前的权限自检。

接口名称

IsElevated

DLL 调用

int IsElevated(long ola);

参数说明

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

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int ret = ola.IsElevated();
csharp
using OLAPlug;

var ola = new OLAPlugServer();
int ret = ola.IsElevated();
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
ret = ola.IsElevated()
java
import com.olaplug.OLAPlugServer;

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

OLAPlugServer ola;
int32_t ret = ola.IsElevated();

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
IsElevated(instance);
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int IsElevated(long ola);

long instance = CreateCOLAPlugInterFace();
IsElevated(instance);
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

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

返回值

含义
1当前进程以管理员权限(UAC 已提升)运行
0当前进程提升(标准用户令牌)

注意事项

  • 检测的是本进程权限,与 OLA 对象内部状态无关;ola 参数用于与其它 DLL 接口调用方式保持一致,并支持远程调用转发。
  • 「管理员组成员但未提升」的进程仍返回 0;需对宿主 exe 右键 → 以管理员身份运行,或在已提升的父进程中加载插件。
  • 部分接口(如 BindWindowEx 的 Hook 模式)在内部会校验管理员权限,未提升时可能直接失败;建议在业务初始化阶段先调用本接口并给出提示。
  • 本接口仅适用于 Windows。