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;

 

相关阅读 >>

cnpack sqlite tool 2.04

Delphi 把字符串复制到剪贴板

Delphi 中文字符串截取

Delphi 获取windows系统网卡mac地址

fastmm5

Delphi xe6通过wifiapi得到wifi信息

Delphi deletefile 删除文件

Delphi 整理内存

Delphi 判断一个颜色是否是亮色

Delphi indy smtp 发送邮件

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



打赏

取消

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

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

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

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

评论

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

    正在狠努力加载,请稍候...