UIAccess 提权 API 封装DLL版本,提供标准调用接口,支持 C#/VB.NET/Python/C++ 等多语言调用
本项目是基于uiaccess项目的DLL二次封装版本,支持从外部程序使用API调用UIAccess提权功能。
程序以管理员权限启动,然后调用该DLL的API检测自身是否具有UIAccess权限。如果还未获取权限,调用该DLL的API遍历进程列表,尝试获取同一Session下winlogon.exe的令牌 ,并用这个令牌创建另一个具有TokenUIAccess的令牌,然后用它启动另一个程序实例。
UIAccess 级别顶置功能需要 Windows 8 以上版本才可使用,Windows 7 及以下版本无需此功能支持。UIAccess 提权需要以管理员身份运行。
UIAccess Privilege Elevation API Wrapper DLL - Provides standard calling interfaces for C#/VB.NET/Python/C++ and other languages.
This project is a DLL-based wrapper of the uiaccess project, providing an API interface for external programs to invoke UIAccess privilege elevation.
The program launches with administrator privileges and calls the DLL's API to check whether it already has UIAccess permission. If not, it calls another API to enumerate running processes, attempting to obtain the token of winlogon.exe running under the same session. It then duplicates this token into a new token with TokenUIAccess flag set, and uses it to launch a new instance of the program.
UIAccess privilege elevation requires Windows 8 or later. Windows 7 and below do not support this feature. UIAccess elevation must be run with administrator privileges.
| API 接口 API Interface | 返回值 Return Value | 说明 Description |
|---|---|---|
PrepareForUIAccess() |
uint |
提权至 UIAccess Elevate to UIAccess |
CheckUIAccessStatus() |
bool |
查询权限状态 Query privilege status |
GetLastErrorMessage() |
void |
获取错误描述 Get error description |
打开 Visual Studio 开发者命令提示符,切换到本项目目录,执build命令即可编译。(生成的 DLL 架构取决于所选的命令提示符版本,如 x86 / x64)
Open the Visual Studio Developer Command Prompt, navigate to the project directory, and run thebuildcommand to compile. (The architecture of the generated DLL depends on the version of the command prompt you opened, e.g., x86 or x64.)
C#
[DllImport("UIAccessHelper.dll")]
static extern uint PrepareForUIAccess();
[DllImport("UIAccessHelper.dll")]
static extern bool CheckUIAccessStatus();
// 检查权限
if (!CheckUIAccessStatus())
{
// 提权(自动重启进程)
uint result = PrepareForUIAccess();
if (result == 0) Console.WriteLine("提权成功");
}
VB.NET
<DllImport("UIAccessHelper.dll")>
Private Shared Function PrepareForUIAccess() As UInteger
End Function
<DllImport("UIAccessHelper.dll")>
Private Shared Function CheckUIAccessStatus() As Boolean
End Function
' 检查权限
If Not CheckUIAccessStatus() Then
' 提权(自动重启进程)
Dim result As UInteger = PrepareForUIAccess()
If result = 0 Then Console.WriteLine("提权成功")
End If
Python
import ctypes
from ctypes import wintypes
dll = ctypes.WinDLL("UIAccessHelper.dll")
dll.PrepareForUIAccess.restype = wintypes.DWORD
dll.CheckUIAccessStatus.restype = wintypes.BOOL
# 检查权限
if not dll.CheckUIAccessStatus():
# 提权(自动重启进程)
result = dll.PrepareForUIAccess()
if result == 0:
print("提权成功")
Java(JNA)
public interface UIAccess extends Library {
UIAccess INSTANCE = Native.load("UIAccessHelper", UIAccess.class);
int PrepareForUIAccess();
boolean CheckUIAccessStatus();
}
// 检查权限
if (!UIAccess.INSTANCE.CheckUIAccessStatus()) {
// 提权(自动重启进程)
int result = UIAccess.INSTANCE.PrepareForUIAccess();
if (result == 0) System.out.println("提权成功");
}
转到发布页可以下载编译好的DLL文件。
Visit the Release Page to download the compiled DLL files.
本项目基于 LGPL-2.1 协议授权。
The project license under the LGPL-2.1.