如果你使用的是 Unicode 版本的 Inno Setup,那么以下是更为专业的解决方法。
    这是 mlaan 提及的再一种方法。

QUOTE(     CodeAutomation3.iss)

; -- CodeAutomation2.iss --
    ;
    ; This script shows how to use IUnknown based COM Automation objects.
    ;
    ; REQUIRES UNICODE INNO SETUP!
    ;
    ; Note: some unneeded interface functions which had special types have been     replaced
    ; by dummies to avoid having to define those types. Do not remove these     dummies as
    ; that would change the function indices which is bad. Also, not all     function
    ; protoypes have been tested, only those used by this example.
   
    [Setup]
   
AppName=My Program
    AppVerName=My Program version 1.5
    CreateAppDir=no
    DisableProgramGroupPage=yes
    DefaultGroupName=My Program
    UninstallDisplayIcon={app}\MyProg.exe
    OutputDir=userdocs:Inno Setup Examples Output
   
    [Code]
   
   
{---     IShellLink ---}
   
    const
    CLSID_ShellLink     = '{00021401-0000-0000-C000-000000000046}';
    SLDF_RUNAS_USER = $2000;
   
    type
    IShellLinkW = interface(IUnknown)
      '{000214F9-0000-0000-C000-000000000046}'
      procedure Dummy;
      procedure Dummy2;
      procedure Dummy3;
      function GetDescription(pszName: String; cchMaxName: Integer): HResult;
      function SetDescription(pszName: String): HResult;
      function GetWorkingDirectory(pszDir: String; cchMaxPath: Integer): HResult;
      function SetWorkingDirectory(pszDir: String): HResult;
      function GetArguments(pszArgs: String; cchMaxPath: Integer): HResult;
      function SetArguments(pszArgs: String): HResult;
      function GetHotkey(var pwHotkey: Word): HResult;
      function SetHotkey(wHotkey: Word): HResult;
      function GetShowCmd(out piShowCmd: Integer): HResult;
      function SetShowCmd(iShowCmd: Integer):     HResult;
      function GetIconLocation(pszIconPath: String; cchIconPath: Integer;
        out     piIcon:     Integer): HResult;
      function SetIconLocation(pszIconPath: String; iIcon: Integer): HResult;
      function SetRelativePath(pszPathRel: String; dwReserved: DWORD): HResult;
      function Resolve(Wnd: HWND; fFlags: DWORD):     HResult;
      function SetPath(pszFile: String): HResult;
    end;
   
    IPersist = interface(IUnknown)
      '{0000010C-0000-0000-C000-000000000046}'
      function GetClassID(var classID: TGUID): HResult;
    end;
   
    IPersistFile = interface(IPersist)
      '{0000010B-0000-0000-C000-000000000046}'
      function IsDirty: HResult;
      function Load(pszFileName: String; dwMode: Longint): HResult;
      function Save(pszFileName: String; fRemember: BOOL): HResult;
      function SaveCompleted(pszFileName: String): HResult;
      function GetCurFile(out pszFileName: String): HResult;
      function GetFlags(out Flags: DWORD): HResult;
      function SetFlags(Flags: DWORD): HResult;
    end;
   
    IShellLinkDataList = interface(IUnknown)
      '{45E2B4AE-B1C3-11D0-B92F-00A0C90312E1}'
      function AddDataBlock(pDataBlock : DWORD) :     HResult;
      function CopyDataBlock(dwSig : DWORD; var ppDataBlock : DWORD) : HResult;
      function RemoveDataBlock(dwSig : DWORD) :     HResult;
      function GetFlags(var pdwFlags : DWORD) : HResult;
      function SetFlags(dwFlags : DWORD) : HResult;
    end;
   
    procedure IShellLinkButtonOnClick(Sender:     TObject);
    var
    Obj: IUnknown;
    SL: IShellLinkW;
    PF: IPersistFile;
    SDL: IShellLinkDataList;
    Flags: DWord;
    begin
    { Create the     main ShellLink COM Automation object }
    Obj :=     CreateComObject(StringToGuid(CLSID_ShellLink));
   
    { Set the     shortcut properties }
    SL :=     IShellLinkW(Obj);
    OleCheck(SL.SetPath(ExpandConstant('{srcexe}')));
    OleCheck(SL.SetArguments(''));
    OleCheck(SL.SetShowCmd(SW_SHOWNORMAL));
   
    // 设置 以其他用户身份运行
    Flags := 0;
    SDL := IShellLinkDataList(Obj);
    OleCheck(SDL.GetFlags(Flags));
    OleCheck(SDL.SetFlags(Flags or SLDF_RUNAS_USER));
   
    { Save the     shortcut }
    PF :=     IPersistFile(Obj);
    OleCheck(PF.Save(ExpandConstant('{commondesktop}\CodeAutomation2 Test.lnk'), True));
   
    MsgBox('Saved a     shortcut named ''CodeAutomation2 Test'' on the common desktop.', mbInformation, mb_Ok);
    end;
   
    {---}
   
    procedure CreateButton(ALeft, ATop: Integer; ACaption:     String; ANotifyEvent: TNotifyEvent);
    begin
    with TButton.Create(WizardForm)     do begin
      Left := ALeft;
      Top := ATop;
      Width := (WizardForm.CancelButton.Width*3)/2;
      Height := WizardForm.CancelButton.Height;
      Caption := ACaption;
      OnClick := ANotifyEvent;
      Parent := WizardForm.WelcomePage;
    end;
    end;
   
    procedure InitializeWizard();
    var
    Left, LeftInc,     Top, TopInc: Integer;
    begin
    Left :=     WizardForm.WelcomeLabel2.Left;
    LeftInc := (WizardForm.CancelButton.Width*3)/2 + ScaleX(8);
    TopInc := WizardForm.CancelButton.Height + ScaleY(8);
    Top := WizardForm.WelcomeLabel2.Top + WizardForm.WelcomeLabel2.Height -     4*TopInc;
   
    CreateButton(Left, Top, '&IShellLink...', @IShellLinkButtonOnClick);
    end;

Inno Setup怎样创建一个自动申请管理员身份运行的快捷的更多相关文章

  1. 让bat文件自动以管理员身份运行

    · 让bat文件自动以管理员身份运行 如何让bat文件自动以管理员身份运行,将这段写在bat文件的前头即可 : %1 mshta vbscript:CreateObject("Shell.A ...

  2. 如何自动以管理员身份运行.NET程序?

    原文:如何自动以管理员身份运行.NET程序? windows 7和vista提高的系统的安全性,同时需要明确指定“以管理员身份运行”才可赋予被运行软件比较高级的权限,比如访问注册表等.否则,当以普通身 ...

  3. 让程序自动以管理员身份运行(用到了DuplicateToken,模拟管理员的身份,不可思议)

    using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...

  4. C# 让程序自动以管理员身份运行

    exe在Vista或Win7下不以管理员权限运行,会被UAC(用户帐户控制)阻止访问系统某些功能,如修改注册表操作等;如何让exe以管理员权限运行呢,方法有两种,一个是直接修改exe属性;另一个是在程 ...

  5. CMD批处理(5)——自动以管理员身份运行批处理脚本

    在日常运维工作中,为方便对windows用户进行系统安装或配置等,使用Windows自带的批处理(bat文件)是一种最为简单快速的方法. 批处理脚本不会默认已管理员身份运行,一般情况下,我会将脚本命名 ...

  6. Delphi Xe2 后的版本如何让Delphi程序启动自动“以管理员身份运行"

    由于Vista以后win中加入的UAC安全机制,采用Delphi开发的程序如果不右键点击“以管理员身份运行”,则会报错. 在XE2以上的Delphi版本处理这个问题已经非常简单了. 右建点击工程,选择 ...

  7. C#程序用Inno Setup打包,以管理员身份运行的处理方法

    一.C#项目端的处理 目标:快捷方式有带盾的标识 在源码的Properties目录中找到 app.manifest,将其中level="asInvoker" 改成 level=&q ...

  8. C#如何调用以管理员身份运行的cmd命令提示符

    windows自从vista.win7.win8/8.1以及win10以来,命令行提示符分为两种模式,一种是普通用户模式,一种的管理员模式,很多情况下,我们的程序需要在命令提示符(管理员身份)的状况下 ...

  9. C#程序如何以管理员身份运行

    VISTA 和 Windows 7 都使用了UAC来控制程序访问,对于一些需要使用管理员身份运行的程序就得右键以管理员身份运行. C# 编程中可以使程序自动使用管理员身份运行,也就是我们常常看到一些程 ...

随机推荐

  1. Guid和Sequence做主键的比较

    记得A项目组是一个物流管理系统,后台采用了Oracle数据库.在系统中的核心表托运单表中,关于主键采用何种数据类型,是 sequence 还是用GUID , 大家起了争论. 从网络搜索得到的结论看,一 ...

  2. BZOJ 1668 馅饼里的财富

    RT. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  3. HDU 5015

    http://acm.hdu.edu.cn/showproblem.php?pid=5015 矩阵是表示状态转移的利器 这题m很大,n非常小,所以开始的思考角度是能否从当前列推出下一列.有了这个角度, ...

  4. Eclipse+Python+Selenium自动化测试框架搭建

    1.下载Eclipse:http://www.eclipse.org/downloads/ 2.下载JDK:http://www.oracle.com/technetwork/java/javaee/ ...

  5. javascript选择器querySelector和querySelectorAll的使用和区别

    querySelector 和 querySelectorAll 方法是 W3C Selectors API规范中定义的.他们的作用是根据 CSS 选择器规范,便捷定位文档中指定元素. 目前几乎主流浏 ...

  6. Redis中struct运用

    c#操作缓存例如redis比较推荐ServiceStack 在redis中运用key-value存储数据,但是遇到结构体该如何处理,是类可通过get<type>(key)获得,那struc ...

  7. 服务器使用recast navigation

    在3D MMO或者其他类型的游戏中,通常需要进行寻路处理,地图针对寻路有多种方案,比如划分格子,凸多边形等,本篇介绍一种比较常用的navigation mesh的方式来进行寻路.不过整套navmesh ...

  8. eclipse常用插件

    1. eclipse安装主题插件:http://www.eclipsecolorthemes.org/ 2. eclipse terminal插件:在eclipse中集成终端,使用非常方便,不用单独打 ...

  9. 关于scrolltop 兼容 IE6/7/8, Safari,FF的方法

    1.各浏览器下 scrollTop的差异IE6/7/8:对于没有doctype声明的页面里可以使用  document.body.scrollTop 来获取 scrollTop高度 :对于有docty ...

  10. js倒计时跳转链接

    (function(){ var loadUrl = 'http://www.cnblogs.com/naokr/',//跳转链接 loadTime = 3000,//跳转时间 reTime = 10 ...