zoukankan      html  css  js  c++  java
  • Inno Setup怎样创建一个自动申请管理员身份运行的快捷

      
       

    如果你使用的是 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;
       
       

       
  • 相关阅读:
    Django创建博客
    使用LR的socket协议进行进行性能测试,转解决方案
    loadrunner测试c/s架构的应用系统
    C/S架构的性能测试
    Win10离线安装.NET Framework 3.5的方法技巧(附离线安装包下载)
    VMWare虚拟机无法连接网络!
    Microsoft Windows XP SP3 官方原版镜像下载,绝对原版加系列号!
    软件cs页面分辨率测试
    C/S结构软件测试要点汇总
    手机访问网站自动跳转到手机版
  • 原文地址:https://www.cnblogs.com/key-ok/p/4104819.html
Copyright © 2011-2022 走看看