在我的[Files]
部分,我有以下内容:
; Database password decryption (for PTS importing)
Source: "..\..\..\PTSTools\PTSTools\bin\x86\Release\PTSTools.dll"; DestDir: "{app}"; \
DestName: "PTSTools_x86.dll"; Flags: ignoreversion
Source: "..\..\..\PTSTools\PTSTools\bin\x64\Release\PTSTools.dll"; DestDir: "{app}"; \
DestName: "PTSTools_x64.dll"; Flags: ignoreversion; Check: IsWin64
在[Run]
部分,我有:
Filename: "{dotnet40}\regasm.exe"; Parameters: "PTSTools_x86.dll /codebase"; \
WorkingDir: "{app}"; Flags: runhidden
Filename: "{dotnet4064}\regasm.exe"; Parameters: "PTSTools_x64.dll /codebase"; \
WorkingDir: "{app}"; Flags: runhidden; Check: IsWin64
最后,在[UninstallRun]
部分,我有:
Filename: {dotnet40}\regasm.exe; Parameters: /u PTSTools_x86.dll; WorkingDir: {app}; \
Flags: runhidden
Filename: {dotnet4064}\regasm.exe; Parameters: /u PTSTools_x64.dll; WorkingDir: {app}; \
Flags: runhidden; Check: IsWin64;
现在,在我的程序版本中,我已将这两个DLL文件的功能整合到另一组DLL文件中:
Source: "..\..\..\MSAToolsLibrary\MSAToolsLibrary\bin\x86\Release\MSAToolsLibrary.dll"; \
DestDir: "{app}"; DestName: "MSAToolsLibrary_x86.dll"; Flags: ignoreversion
Source: "..\..\..\MSAToolsLibrary\MSAToolsLibrary\bin\x64\Release\MSAToolsLibrary.dll"; \
DestDir: "{app}"; DestName: "MSAToolsLibrary_x64.dll"; Flags: ignoreversion; \
Check: IsWin64
因此,不再需要PTSTool
DLL文件。现在,我知道如果它们存在,我可以简单地删除它们:
[InstallDelete]
Type: files; Name: "{app}\PTSTools_x64.dll"
Type: files; Name: "{app}\PTSTools_x86.dll"
但据我所知,这不会像[UninstallRun]
中那样触发取消注册DLL文件。
我该怎么做?在安装过程中删除和取消注册DLL文件(如果存在)?
答案 0 :(得分:1)
我认为你不能使用标准部分轻松实现这一点。
[Run]
条目仅在[InstallDelete]
之后发生。在删除DLL之前,您需要另外一种方法来首先取消注册。
所以你需要Pascal脚本。
将BeforeInstall
parameter添加到[InstallDelete]
并取消注册DLL programificaly。
或者将AfterInstall
parameter添加到[Run]
并以编程方式删除DLL。
后者对你的工作较少,因为你已经知道如何使用[Run]
来(注册)。
[Run]
Filename: {dotnet40}\regasm.exe; Parameters: /u PTSTools_x86.dll; WorkingDir: {app}; \
Check: FileExists(ExpandConstant('{app}\PTSTools_x86.dll')); \
AfterInstall: DoDeleteFile(ExpandConstant('{app}\PTSTools_x86.dll')); \
Flags: runhidden
Filename: {dotnet4064}\regasm.exe; Parameters: /u PTSTools_x64.dll; WorkingDir: {app}; \
Check: IsWin64 and FileExists(ExpandConstant('{app}\PTSTools_x64.dll')); \
AfterInstall: DoDeleteFile(ExpandConstant('{app}\PTSTools_x64.dll')); \
Flags: runhidden
[Code]
{ Cannot use built-in DeleteFile directly in AfterInstall as it's a function,
{ not a procedure. And this way we can add some error handling too. }
procedure DoDeleteFile(FileName: string);
begin
if DeleteFile(FileName) then
begin
Log(Format('"%s" deleted', [FileName]));
end
else
begin
MsgBox(Format('Failed to delete "%s"', [FileName]), mbError, MB_OK);
end;
end;