如果你使用的是 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. 【汇总】Android 常用方法整理

    1.解决ActionBar OverFlow按钮不显示.(在oncreate中调用即可) private void setOverflowShowingAlways() { try { ViewCon ...

  2. 虚机centos和本机Windows之间文件的拷贝无法用xftp时用FileZilla也行

    步骤如下: 1.如果Centos没有安装ssh,则需要先安装: 2.查看虚拟机中IP地址,命令如下: ifconfig 3.在windows中安装ftp软件 FileZilla启动软件如图: 6  这 ...

  3. 安装ant问题

    1  设置path, 在windwos 7下要重启 2  重启后,cmd----ant -version  Unable to locate tools.jar. Expected to find i ...

  4. CentOS7 下 安装 supervisor以及使用

    CentOS7 下 安装 supervisor 以及使用 手动安装 [注] linux环境必须安装 python 1.获取supervisor包:[https://pypi.python.org/py ...

  5. HDU5402 暴力模拟

    因为题目中没有说是否是正整数,导致我们以为是DP,没敢做...太可惜了,不过现场赛绝对不会出现这种情况,毕竟所有的提问是都可以看见的. 题意:告诉一个矩阵,然后求从(1,1)到(n,m)能走过的最大和 ...

  6. Direct3D 10学习笔记(三)——文本输出

    本篇将简单整理Direct3D 10的文本输出的实现,具体内容参照< Introduction to 3D Game Programming with DirectX 10>(中文版有汤毅 ...

  7. ORA-00942:table or view does not exist

    好好的表都建成功了,在PL/SQL中编辑数据时给我来这个提示,起的我没办法了.查到如下: oracle建表时有一个严重的问题,在此写出来,提醒大家注意: 先简单写一下错误内容,如各位已经发现过此问题并 ...

  8. linux awk的使用

    awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行各 ...

  9. OpenMP编程总结表

    本文对OpenMP 2.0的全部语法——Macro(宏定义).Environment Variables(环境变量).Data Types(数据类型).Compiler Directives(编译指导 ...

  10. Poco C++ MySQl demo

    #include "Poco/Exception.h"#include "Poco/Data/Session.h"#include "Poco/Dat ...