Inno设置 - 以管理员身份注册组件

时间:2017-04-04 18:27:48

标签: excel inno-setup

基于优秀的Excel加载项安装程序(Daniel的XL工具箱),我构建了一个安装文件,其中包括需要注册一些ActiveX的

[Files]
; The include file makes adds all .XLA and .XLAM files contained in the
; SOURCEDIR to the project.

Source: "c:\source\path\MSCOMCTL.OCX"; \
    DestDir: "\users\public\EzPasteFiles"; Flags: regserver      
Source: "c:\source\path\DAS_AX_Knob.dll"; \
    DestDir: "\users\public\EzPasteFiles"; Flags: regserver    
Source: "c:\source\path\GIF89.DLL"; \
    DestDir: "\users\public\EzPasteFiles"; Flags: regserver 

我需要安装插件,然后在开始注册文件之前检查管理员权限,如果用户没有,则会显示一条消息,要求输入管理员密码以便进行注册。我知道它可以在设置开始时完成,但如果它是标准用户帐户,则不会激活插件。插件需要注册组件,标准用户无法正确安装。

我正在寻找这样的东西在注册开始之前开火:

MyProgChecked :=  not(IsAdminLoggedOn or IsPowerUserLoggedOn); 
if MyProgChecked = True then
begin
  MsgBox(
    'Kindly notice:' #13#13 
    'It seems as you are not looged as an administrator' #13#13
    'Please abort and reinstall EzPaste AS an administrator' #13#13
    '(To install As an Adminstrator, just save the exe setup anywhere then Right Click on it to get to this feature or ask your IT administrator for proper directives)',
    mbConfirmation, MB_OK);
  { Popup message asking for Pwd }
  ExitProcess(0); 
end;

我自然愿意采取任何其他方法

我也很高兴了解没有管理员权限的域用户(Windows服务器)应如何继续安装插件。

1 个答案:

答案 0 :(得分:3)

您可以以管理员身份执行regsvr32.exe"",这样:

[Files]
Source: "MyDll.dll"; DestDir: "{app}"; AfterInstall: RegMyDll

[Code]

procedure RegMyDll;
var
  Path: string;
  RegSvr: string;
  Params: string;
  Registered: Boolean;
  ErrorCode: Integer;
begin
  Path := ExpandConstant(CurrentFilename);
  RegSvr := 'regsvr32.exe';
  Params := Format('/s "%s"', [Path]);
  Log(Format('Registering %s using "%s" %s', [Path, RegSvr, Params]));
  Registered :=
    ShellExec('runas', RegSvr, Params, '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
  if Registered and (ErrorCode = 0) then
  begin
    Log(Format('Registered %s', [Path]));
  end
    else
  begin
    MsgBox(Format('Registering %s failed with code %d', [Path, ErrorCode]), mbError, MB_OK);
  end;
end;

Elevated registration

替代实现是仅为注册创建需要管理员权限的子安装程序。

有关类似示例,请参阅Inno Setup - Access unprivileged account folders from installer that requires privileges

或使用相反的方法。使用

需要管理员权限
[Setup]
PrivilegesRequired=admin

(默认)

但是将文件部署到原始用户文件夹 请参阅我对Inno Setup always installs into admin's AppData directory的回答。

相关问题