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 jpeg图片压缩

Delphi 中的字符串

Delphi getcomputername() getusername() 获取本机当前用户名

Delphi+mysql:tadoquery使用插入中文乱码解决方法

Delphi编写dll(以及静态和动态方式调用)

Delphi 字符串、文件路径 排序算法

Delphi操作文本文件简介

Delphi 多线程(tthread类的实现)实例

Delphi 操作前,删除前,覆盖前,询问对话框

Delphi: ttreeview 中禁止双击事件展开或关闭节点

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



打赏

取消

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

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

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

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

评论

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