2013-05-01 80 views
1

如何構建我的Inno Setup腳本,以便在用戶第一次安裝我的應用程序時自動註冊dll,但如果有先前版本,則註銷以前的版本,然後註冊新版本(假設界面不同)?用Inno Setup更新DLL服務器

我目前使用的REGSERVER和ignoreversion國旗在我的文件部分,如下圖所示:

[Setup] 
... 

[Languages] 
... 

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

在我的谷歌搜索,我發現UnregisterServer但我不知道如何將它添加到我的腳本。我很樂意開始修改,看看它是如何工作的,但我不想做任何會弄亂我的註冊表的事情。

有一個類似的帖子here但它並沒有解決這是如何實際完成的。

編輯

帕斯卡爾黑客周圍後我能到以下添加到[代碼]部分,它的工作。 有誰知道如何使用{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; 
+1

在'InitializeSetup'時間擴展'{app}'常量爲時過早。此外,'{app}'常量包含當前選擇的安裝文件夾,而您想檢查以前的應用程序文件夾。您可以從'InitializeWizard'事件方法中最快從'WizardForm.PrevAppDir'屬性獲取最後一個文件夾,例如['這種方式'](http://pastebin.com/pkXAgEzH)。 – TLama 2013-05-02 15:03:22

+0

Tlama,謝謝你!我想知道爲什麼我不能引用{app}。 WizardForm.PrevAppDir如何工作?我是否必須保持我的.iss腳本相同,以便嚮導知道此嚮導之前已被使用過? – 2013-05-02 15:19:31

+0

通常情況下,你不應該改變COM接口,以便它們不兼容(你應該只添加,從不減)。因此永遠不需要註銷舊版本。當然,如果它是一個應用程序私有庫而不是共享庫,那麼它會有更多的餘地。 – Miral 2013-05-02 20:46:08

回答

2

怎麼樣使用BeforeInstallAfterInstall參數文件?

用法爲:

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

我喜歡這個,聽起來很簡單。我會看看我是否可以通過eod來測試。我還沒有使用AfterInstall,但很瞭解它。 – 2013-05-02 15:22:37

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;

端;