• 为Delphi程序增加UAC功能(管理员身份运行exe)


    为Delphi程序增加UAC功能(管理员身份运行exe)


    相关资料:http://bbs.csdn.net/topics/320071356#

    操作方法:

    在SourceVCL目录下应该有这样两个文件sample.manifest和WindowsXP.rc,可以通过如下方法处理:

    1.sample.manifest处理
    ①打开“sample.manifest”
    ②修改sample.manifest把其中的
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
    <requestedPrivileges>
    <requestedExecutionLevel
    level="asInvoker"
    uiAccess="false"/>
    </requestedPrivileges>
    </security>
    </trustInfo>
    改为
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
    <requestedPrivileges>
    <requestedExecutionLevel
    level="requireAdministrator"
    uiAccess="false"/>
    </requestedPrivileges>
    </security>
    </trustInfo>
    ③另存为requireAdmin.manifest

    2.WindowsXP.rc处理
    ①打开WindowsXP.rc
    ②将内容编辑成
    1 24 "requireAdmin.manifest"
    ③并另存为requireAdmin.rc

    3.编译资源文件
    ①新建一个文件夹
    ②复制brcc32.exe、rw32core.dll、requireAdmin.manifest、requireAdmin.rc到文件夹中。
    ③新建一个TXT,写入“brcc32 requireAdmin.rc”,保存后改名为“requireAdmin.bat”
    ④双击requireAdmin.bat

    4.放置资源文件
    ①复制“requireAdmin.res”
    ②放到“$(BDS)lib”目录下

    5.设置主题
    ①打开工程
    ②打开Project菜单下的Options...菜单项,将Application下面的"Enable runtime themes"的勾选去掉.

    6.引用资源
    ①打开Project菜单下的View Source菜单项

    {$R *.res}
    下面添加一行
    {$R requireAdmin.res}

    7.重新编译即可。

    另一种方法:

    相关资科:

        http://bbs.csdn.net/topics/190003519

        http://www.cppblog.com/SpringSnow/archive/2009/04/22/80719.html

    //以管理员身份运行
    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;

  • 相关阅读:
    解析Jquery取得iframe中元素的几种方法
    jquery 金额转换成大写
    MVC 后台管理框架 FineUIMvc 在线示例
    7个高性能JavaScript代码高亮插件
    layer弹出信息框API
    【Bootstrap-插件使用】Jcrop+fileinput组合实现头像上传功能
    一个基于Microsoft Azure、ASP.NET Core和Docker的博客系统
    ASP.NET MVC 3 技术(九) 301永久重定向不带www域名到带www的域名
    ASP.NET MVC 3 网站优化总结(三)Specify Vary: Accept-Encoding header
    ASP.NET MVC 3 网站优化总结(一) 使用 Gzip 压缩
  • 原文地址:https://www.cnblogs.com/westsoft/p/5962369.html
Copyright © 2020-2023  润新知