Inno Setup - 以管理员身份注册组件 [英] Inno Setup - Register components as an administrator

查看:1003
本文介绍了Inno Setup - 以管理员身份注册组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于优秀的Excel加载项安装程序(Daniel's XL Toolbox),我已经构建了一个安装文件,其中需要注册一些ActiveX的

  [文件] 
;包含文件使得
中包含所有.XLA和.XLAM文件。 SOURCEDIR到项目。

资料来源:c:\source\path\MSCOMCTL.OCX; \
DestDir:\users\public\EzPasteFiles;标志:regserver
资料来源:c:\source\path\DAS_AX_Knob.dll; \
DestDir:\users\public\EzPasteFiles;标志:regserver
资料来源:c:\source\path\GIF89.DLL; \
DestDir:\users\public\EzPasteFiles;标志:regserver

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



在注册开始之前,我正在寻找类似这样的消息:

  MyProgChecked:= not(IsAdminLoggedOn或IsPowerUserLoggedOn); 
如果MyProgChecked = True然后
开始
MsgBox(
'请注意:'#13#13
'似乎你不会因为管理员# 13#13
'请中止并重新安装EzPaste作为管理员'#13#13
'(要安装作为管理员,只需将exe设置保存到任何地方,然后右键单击即可获得此功能或请您的IT管理员正确的指示)',
mbConfirmation,MB_OK);
{弹出消息请求Pwd}
ExitProcess(0);
结束

我自然对任何其他方法开放



我也很高兴知道一个没有管理员权限的域用户(Windows服务器)应该继续安装加载项。

解决方案

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

  [文件] 
资料来源:MyDll.dll; DestDir:{app}; AfterInstall:RegMyDll

[代码]

程序RegMyDll;
var
路径:string;
RegSvr:string;
参数:string;
注册:Boolean;
ErrorCode:整数;
begin
路径:= ExpandConstant(CurrentFilename);
RegSvr:='regsvr32.exe';
参数:=格式('/ s%s',[路径]);
日志(格式('使用'%s'%s'注册%s),[Path,RegSvr,Params]));
注册:=
ShellExec('runas',RegSvr,Params,',SW_HIDE,ewWaitUntilTerminated,ErrorCode);
如果注册和(ErrorCode = 0)然后
开始
日志(格式('注册%s',[路径]));
end
else
begin
MsgBox(Format('Registering%s failed with code%d',[Path,ErrorCode]),mbError,MB_OK);
结束
结束






替代实现是创建用于注册的子服务器,只需要管理员权限。



对于类似的示例,请参阅 Inno安装程序 - 从需要权限的安装程序访问非特权帐户文件夹






或使用相反的方法。需要管理员权限使用

  [安装] 
PrivilegesRequired = admin
/ pre>

(这是默认值)



但是将文件部署到原始用户文件夹。

请参阅我的答案 Inno安装程序始终安装在管理员的AppData目录


Based on the excellent Excel add-in installer (Daniel's XL Toolbox), I have built a setup file that among other things needs to register some ActiveX's

[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 

I need the addin to install, then before starting to register the files a check is done about administrator rights and if the user has none, a message is displayed asking for entering the admin password so that registration can take place. I am aware that it can be done at the beginning of the setup, but then the addin will not be activated, if it is a standard user account. The addin needs registered components, a standard user can't install it properly.

I am looking for something like this to fire before the registration starts:

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;

I am naturally open for any other approach

I'll be glad also to understand how a domain user (Windows server) without admin rights should proceed to install the addin.

解决方案

You can execute regsvr32.exe "as administrator", this way:

[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;


Alternative implementation is to create subinstaller for the registration only that will require Administrator privileges.

For a similar example, see Inno Setup - Access unprivileged account folders from installer that requires privileges.


Or use an opposite approach. Require administrator privileges using

[Setup]
PrivilegesRequired=admin

(which is default)

But deploy files to the original user folder.
See my answer to Inno Setup always installs into admin's AppData directory.

这篇关于Inno Setup - 以管理员身份注册组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆