如何检测可执行文件是否需要UAC提升(C#pref) [英] How to detect if executable requires UAC elevation (C# pref)

查看:76
本文介绍了如何检测可执行文件是否需要UAC提升(C#pref)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测可执行文件是否需要UAC提升? 到目前为止,我有两个想法: 可执行程序图标的图片识别,以检查其上是否有UAC屏蔽图标 和来自维基百科的信息: http://en.wikipedia.org/wiki/User_Account_Control

how can I detect if executable requires UAC elevation? So far I came to two ideas: picture recognition of executable's icon to check if UAC shield icon is on it and information from wikipedia: http://en.wikipedia.org/wiki/User_Account_Control

可以通过使用CreateProcess()并将dwCreationFlags参数设置为CREATE_SUSPENDED来以编程方式检测可执行文件是否需要提升.如果需要海拔,则将返回ERROR_ELEVATION_REQUIRED.[16]如果不需要提升,则将返回成功返回码,此时您可以在新创建的暂停过程中使用TerminateProcess().如果您已经在提升的进程中执行该操作,则这将不允许您检测到可执行文件需要提升.

it is possible to programmatically detect if an executable will require elevation by using CreateProcess() and setting the dwCreationFlags parameter to CREATE_SUSPENDED. If elevation is required, then ERROR_ELEVATION_REQUIRED will be returned.[16] If elevation is not required, a success return code will be returned at which point you can use TerminateProcess() on the newly created, suspended process. This will not allow you to detect that an executable requires elevation if you are already executing in an elevated process.

谢谢

推荐答案

尝试使用kernel32.dll导出的CheckElevation函数.这是一个完全未记录的功能,但这是我能够进行反向工程的功能:

Try using the CheckElevation function exported by kernel32.dll. This is a completely undocumented function, but here's what I've been able to reverse-engineer:

ULONG CheckElevation(
    __in PWSTR FileName,
    __inout PULONG Flags, // Have a ULONG set to 0, and pass a pointer to it
    __in_opt HANDLE TokenHandle, // Use NULL
    __out_opt PULONG Output1, // On output, is 2 or less.
    __out_opt PULONG Output2
    );

您必须做一些实验才能找出如何正确调用该函数.到目前为止,我能够解决的问题是,如果Output1不为0,则需要高程.

You'll have to do some experimentation to find out how to call the function properly. What I've been able to work out so far is that if Output1 is not 0, elevation is required.

这篇关于如何检测可执行文件是否需要UAC提升(C#pref)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆