delphi 运行时提升软件到管理员权限


本文整理自网络,侵删。

 

//以管理员身份运行
procedure RunAsAdmin(hWnd: HWND; aFile: string; aParameters: string);
var
sei: TShellExecuteInfoA;
begin
FillChar(sei, SizeOf(sei), 0);
sei.cbSize := SizeOf(sei);
sei.Wnd := hWnd;
sei.fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_FLAG_NO_UI;
sei.lpVerb := 'runas';
sei.lpFile := PChar(aFile);
sei.lpParameters := PChar(aParameters);
sei.nShow := SW_SHOWNORMAL;
if not ShellExecuteEx(@sei) then
RaiseLastOSError;
end

//把按钮设置成需要管理员运行样式,也就是加个图标到按钮上
procedure SetElevationRequireState(aControl: TWinControl; Requiered: Boolean);
const
BCM_FIRST = $1600;//Button control messages
BCM_SETSHILED = BCM_FIRST + $000C;
var
lRequired: Integer;
begin
lRequired := Integer(Requiered);
SendMessage(aControl.Handle, BCM_SETSHIELD, 0, lRequired);
end;

 

相关阅读 >>

Delphi xe10对json的解析应用

理解Delphi中sender用法

Delphi 实现程序 动态 类名

Delphi获取webbrowser中的元素的值

Delphi中编写参数个数可变的函数

Delphi 中英文字符怎么按固定长度截断

Delphi is 与 as 运算符举例

Delphi 设置系统启动文件夹自身开机自动运行

Delphi 安卓图像压缩bitmapcompress

Delphi 判断进程名是否存在,如果存在则结束进程

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...