基于出色的 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 服务器)应该如何继续安装插件。
最佳答案
你可以执行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;
另一种实现方式是为仅需要管理员权限的注册创建子安装程序。
类似的例子,见 Inno Setup - Access unprivileged account folders from installer that requires privileges .
或者使用相反的方法。需要管理员权限使用
[Setup]
PrivilegesRequired=admin
(这是默认值)
但是将文件部署到原始用户文件夹。
查看我对 Inno Setup always installs into admin's AppData directory 的回答.
关于excel - Inno Setup - 将组件注册为管理员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43214918/