如果你使用的是 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. 使用PowerDesigner导出MySQL数据库建模

    数据库服务器在linux上面,客户端本子win8系统 1.安装odbc 1.1 下载odbc,http://dev.mysql.com/downloads/connector/odbc/  Windo ...

  2. 简单理解Struts2中拦截器与过滤器的区别及执行顺序

    简单理解Struts2中拦截器与过滤器的区别及执行顺序 当接收到一个httprequest , a) 当外部的httpservletrequest到来时 b) 初始到了servlet容器 传递给一个标 ...

  3. 第二章:搭建Android开发环境

    通过对本章节内容的阅读,了解了Android底层开发所需要的各种开发工具,以及在Linux环境下怎样搭建Android底层开发环境,在Linux系统上开发Android应用程序,需要安装Linux版本 ...

  4. 深入浅出REST

    不知你是否意识到,围绕着什么才是实现异构的应用到应用通信的“正确”方式,一场争论正进行的如火如荼:虽然当前主流的方式明显地集中在基于SOAP.WSDL和WS-*规范的Web Services领域,但也 ...

  5. google vr开源 cardboard

    https://developers.google.com/cardboard/android/ 待续

  6. HTTP 响应头信息

    HTTP 响应头信息 HTTP请求头提供了关于请求,响应或者其他的发送实体的信息. 在本章节中我们将具体来介绍HTTP响应头信息.

  7. HDU 5113 dfs剪枝

    题意:告诉格子规格,颜色个数,以及每个颜色能涂得格子数目,问是否能够实现相邻两个格子的颜色数目不相同. 分析:因为数据很小,格子最多是5 * 5大小的,因此可以dfs.TLE了一次之后开始剪枝,31m ...

  8. BackTrack5-r3虚拟机安装

    ISOL INUX 3.63 Debian-2008-07-15 Copyright (C) 1994-2008 H. Peter Anvinboot:(按回车) 选择:BackTrack Text ...

  9. CentOS7 监控进程网络流量工具安装

    服务器在做测试的时候,需要监控网络流量,用来了解在不同人数的时候服务器的网络使用量. 我们使用服务器环境是centos7,centos下通常使用iftop,或者nethogs来进行网络流量监控.这2个 ...

  10. a标签不跳转

    <a href="javascript://">父级菜单</a> 结果是这种写法在一些浏览器下不能到达预期效果(无跳转),我没有花时间把这种写法在主流浏览器 ...