如果你使用的是 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. SqlParameter的感悟

    1.在更新DataTable或是DataSet时,如果不采用SqlParameter,那么当输入的Sql语句出现歧义时,如字符串中含有单引号,程序就会发生错误,并且他人可以轻易地通过拼接Sql语句来进 ...

  2. GridView导出excel格式问题

    在导出的点击事件中,代码如下: //指定导出对应单元格为文本样式 string style = @"<style> .test { vnd.ms-excel.numberform ...

  3. SpringMVC之入门

    Spring MVC简介 Spring MVC:Spring MVC也叫Spring Web MVC,属于表现层框架,是Spring中的一份子. Spring MVC执行流程图 第一个SpringMV ...

  4. 19、lambda表达式树

    一.定义: 表达式树又称为表达式目录树,以数据形式表示语言级代码.所有的数据都存储在树结构中,每个结点表示一个表达式(Expression). 二.要点: –Lambda表达式的参数类型可以忽略,因为 ...

  5. 对上次“对字符串进行简单的字符数字统计 探索java中的List功能 ”程序,面向对象的改进

    之前的随笔中的程序在思考后发现,运用了太多的static 函数,没有将面向对象的思想融入,于是做出了一下修改: import java.util.ArrayList; import java.util ...

  6. PHP 爬取网页中表格数据

    public function spider_j($page) { $url="http://aaa/bbb".$page."_0/"; $fcontents= ...

  7. CTO干点啥?

    1.负责技术 2.负责人才 3.负责业务(需求) 4.负责组织

  8. 在Unity中创建可远程加载的.unity3d包

    在一个Unity项目中,发布包本身不一定要包括所有的Asset(译为资产或组件),其它的部分可以单独发布为.unity3d,再由程序从本地/远程加载执行,这部分不在本文讨论范围.虽然Unity并没有直 ...

  9. genymotion模拟器访问本地服务器

    测试环境为:Ubuntu + android studio + genymotion + wifi 我用模拟器访问电脑上的服务器,需要使用的IP为10.0.3.2,其他的什么10.0.2.2和10.0 ...

  10. 【转】Qt下使用glut库

    ps:这个说的很明白,尤其是win10环境下用mingw环境时编程时碰到的问题, 1.加 windows.h 2.在.pro 添加libs     博文地址:Qt下使用glut库   本人使用的环境 ...