2017-08-03 238 views
1

想知道是否有某种我不知道的方式,Inno Setup会重定向配置单元常量。更具体地说,在写入注册表之前,调用此功能的能力为:RegOverridePredefKeyInno Setup:注册表配置单元的重新映射

为了提供一些背景知识,在我的情况下,这将是强制自注册DLL为当前用户(可能不具有管理员凭据)而不是全局注册的首选方式。 (换句话说,请写信给HKEY_CURRENT_USER\Software\Classes而不是HKCR。)还没有找到任何其他的Inno Setup结构来帮助解决这个问题,并且我会避免使用3rd party tools,如果可能的话,这也需要更新。

+0

你知道的方式? –

+1

我不确定你的问题实际上是什么。您是否问Inno Setup是否有内部调用'RegOverridePredefKey'的内置API(指令,标志或任何其他内容),以便您不必以编程方式自己调用它? –

+0

@MartinPrikryl好问题!错误的措辞也许:我不知道任何。我检查了'regserver'标志,想知道它是否可以与某种参数/另一个标志配对,这对我有帮助。我认为我阅读了文档中的所有相关部分,但希望我错过了一些内容。 –

回答

0

不,Inno Setup不支持此操作。

但是从Pascal脚本中调用它并不难。

虽然请注意,您不能使用RegOverridePredefKeyHKEY_LOCAL_MACHINE重定向到HKEY_CURRENT_USER。您只能将其重定向到一个子项:

hNewHKey:...一个开放注册表项的句柄。该句柄由RegCreateKeyExRegOpenKeyEx函数返回。 它不能是预定义的键之一。

所以注册DLL后,你将不得不子项复制到HKEY_CURRENT_USER,并删除它(为RegOverridePredefKey文档建议)。

重定向到一个临时的子项Basic代码:

[Files] 
Source: "MyDllServer.dll"; Flags: ignoreversion dontcopy 

[Code] 

const 
    KEY_WRITE = $20006; 

function RegOverridePredefKey(Key: Integer; NewKey: Integer): Integer; 
    external '[email protected] stdcall'; 

function RegCreateKeyEx(
    Key: Integer; SubKey: string; Reserved: Cardinal; Cls: Cardinal; 
    Options: Cardinal; Desired: Cardinal; SecurityAttributes: Cardinal; 
    var KeyResult: Integer; var Disposition: Cardinal): Integer; 
    external '[email protected] stdcall'; 

function MyDllRegisterServer: Integer; 
    external '[email protected]:MyDllServer.dll stdcall delayload'; 

{ ... } 
begin 
    { Create a subkey to redirect the HKLM to } 
    RegCreateKeyEx(HKEY_CURRENT_USER, 'MyProgTemp', 0, 0, 0, KEY_WRITE, 0, NewKey, Unused); 
    { Redirect HKLM to the created subkey } 
    RegOverridePredefKey(HKEY_LOCAL_MACHINE, NewKey); 
    { Call DllRegisterServer of the .dll } 
    MyDllRegisterServer; 
    { Now you can copy the subkey to HKCU } 
end; 

添加一些错误处理!

该代码适用于Unicode版本的Inno Setup。


对于复制的一部分,你可以从Specify the registry uninstall key location/hive via [Code]重用(提高)我的代码。

+0

谢谢,包括突出显示的观察。我设法错过了那个。 –