使用Inno Setup更新DLL Server

时间:2013-05-01 22:03:31

标签: dll inno-setup pascal updates regsvr32

如果用户第一次安装我的应用程序,我如何构建我的Inno安装脚本以自动注册dll,如果有应用程序,则取消注册以前的版本,然后注册新版本(假设界面不同) ?

我目前使用我的文件部分中的regserver和ignoreversion标志,如下所示:

[Setup]
...

[Languages]
...

[Files]
Source: "C:\example.dll"; DestDir: "{app}"; Flags: ignoreversion regserver

在我的谷歌搜索中,我找到了UnregisterServer,但我不知道如何将其添加到我的脚本中。我很乐意开始修补它,看看它是如何工作的,但我不想做任何会弄乱我的注册表的事情。

有一个类似的帖子here,但它没有解决这是如何实现的。

修改

在Pascal中进行黑客攻击之后我能够将以下内容添加到[Code]部分并且它有效。 有谁知道如何使用{app}常量在下面的代码中动态定义fileName?

[Code]
const
  fileName = 'C:\Program Files\TFolderName\tigercontroller.dll';
var
  serverExists: Boolean;

function InitializeSetup(): Boolean;
begin     
  serverExists := UnregisterServer(False, fileName, False);

  if serverExists then begin
    Result:= True;
    MsgBox('This will update with the most recent version', mbInformation, mb_Ok);
  end else
    Result := True;
end;

2 个答案:

答案 0 :(得分:2)

如何使用文件的 BeforeInstall AfterInstall 参数?

用法是:

[Files]
Source: "MYDLL.DLL"; DestDir: "{app}"; BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall;

BeforeInstall和AfterInstall函数不能有返回值!

procedure MyBeforeInstall();
begin
  // Your code here: If file (old) file exists call UnregisterServer() on old file
  // Use function FileExists(const Name: String): Boolean; or similar for it
  // Also you can delete the file entirely with function DeleteFile(const FileName: string): Boolean;

  // Hint: You can use 'CurrentFileName' variable to get currently processed file 
end;

procedure MyAfterInstall();
begin
  // Your (new) file was processed and now you can do additional tweaks on it
  // 'CurrentFileName' variable is still available 
  // Setup registers all files with the 'regserver' or 'regtypelib' flags as the last step of installation so in this function the file is still not registered!
end;

答案 1 :(得分:0)

尝试这个,它还处理32/64位并排COM服务器:

 function UnregisterCOMServer(sServerCLSID: String): Boolean;
var
   sServerPath: String;
Begin
    Result:=False;
     //search in HKCR (merged view)
     if RegQueryStringValue(HKEY_CLASSES_ROOT, 'CLSID\'+sServerCLSID+'\InprocServer32', '', sServerPath) then
     Begin
        if sServerPath<>'' then
        Begin
            Log('Found COM server CLSID:'+ sServerCLSID +', path:'+sServerPath);
            Result:=UnregisterServer(False, sServerPath, True);
            if Result then Log('COM server '+ sServerCLSID +' unregistered.')
            else Log('UnregisterServer on '+ sServerPath +' failed!');
        end
        else Log('No COM server path found.');
     end
     else Log('COM server CLSID:'+ sServerCLSID +' not found!'+sServerPath);

if Is64BitInstallMode then Begin if RegQueryStringValue(HKEY_CLASSES_ROOT, 'Wow6432Node\CLSID\'+sServerCLSID+'\InprocServer32', '', sServerPath) then Begin if sServerPath<>'' then Begin Log('Found COM server (Wow6432) CLSID:'+ sServerCLSID +', path:'+sServerPath); Result:=UnregisterServer(True, sServerPath, True); if Result then Log('COM server (Wow6432) '+ sServerCLSID +' unregistered.') else Log('UnregisterServer (Wow6432) on '+ sServerPath +' failed!'); end else Log('No COM server (Wow6432) path found.'); end else Log('COM server (Wow6432) CLSID:'+ sServerCLSID +' not found!'+sServerPath); end;

端;