问题
My batch file that I'm trying to run when an Excel plugin needs to be uninstalled is not executing. I'm using the following custom actions to do post install and also on uninstalling the product. The following code:
<CustomAction Id="registeraddin" ExeCommand="[INSTALLFOLDER]RegisterMilerAddIn.bat" Directory="INSTALLFOLDER" Impersonate="no" Execute="deferred" Return="asyncWait" />
<CustomAction Id="unregisteraddinpostinstall" ExeCommand="[INSTALLFOLDER]UnRegisterMilerAddIn.bat" Directory="INSTALLFOLDER" Impersonate="no" Execute="deferred" Return="asyncWait" />
<InstallExecuteSequence>
<Custom Action="registeraddin" After="InstallFiles">NOT Installed</Custom>
<Custom Action="unregisteraddinpostinstall" After="InstallFiles">Installed AND (REMOVE = "ALL")</Custom>
</InstallExecuteSequence>
Produces this error in the log:
MSI (s) (44:04) [11:29:00:437]: Executing op: ActionStart(Name=unregisteraddinpostinstall,,)
MSI (s) (44:04) [11:29:00:437]: Executing op: CustomActionSchedule(Action=unregisteraddinpostinstall,ActionType=1058,Source=C:\Program Files (x86)\Werner Enterprises\Web Miles Excel Addin\,Target=C:\Program Files (x86)\Werner Enterprises\Web Miles Excel Addin\UnRegisterMilerAddIn.bat,)
MSI (s) (44:04) [11:29:00:846]: Note: 1: 1722 2: unregisteraddinpostinstall 3: C:\Program Files (x86)\Werner Enterprises\Web Miles Excel Addin\ 4: C:\Program Files (x86)\Werner Enterprises\Web Miles Excel Addin\UnRegisterMilerAddIn.bat
MSI (s) (44:04) [11:29:00:846]: Note: 1: 2205 2: 3: Error MSI (s) (44:04) [11:29:00:846]: Note: 1: 2228 2: 3: Error 4: SELECT
Message
FROMError
WHEREError
= 1722 CustomAction unregisteraddinpostinstall returned actual error code 100 (note this may not be 100% accurate if translation happened inside sandbox)MSI (s) (44:04) [11:29:10:900]: Note: 1: 2205 2: 3: Error MSI (s) (44:04) [11:29:10:900]: Note: 1: 2228 2: 3: Error 4: SELECT
Message
FROMError
WHEREError
= 1709MSI (s) (44:04) [11:29:10:900]: Product: WebMiles_Addin_Installer -- Error 1722. There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. Action unregisteraddinpostinstall, location: C:\Program Files (x86)\Werner Enterprises\Web Miles Excel Addin\, command: C:\Program Files (x86)\Werner Enterprises\Web Miles Excel Addin\UnRegisterMilerAddIn.bat
That error is obscure to me. I'm not doing real fancy stuff in my batch file either. The installation of the Excel addin works fine (which is the premise of this application). But I can't uninstall the addin, apparently, in the same manner, so goes the aforementioned error in the log.
For completeness, this is the contents of of my register batch (RegisterMilerAddIn.bat):
SET WorkFolder= "C:\Program Files (x86)\Werner Enterprises\Web Miles Excel Addin"
SET _NET_4_Folder= %WinDir%"\Microsoft.NET\Framework\v4.0.30319"
%_NET_4_Folder%\regasm.exe %WorkFolder%\Miler.ExcelAddin.dll /Codebase /tlb:%WorkFolder%\Miler.ExcelAddin.tlb >> C:\temp\log.txt
And unregister batch (UnRegisterMilerAddIn.bat):
SET WorkFolder= "C:\Program Files (x86)\Werner Enterprises\Web Miles Excel Addin"
SET _NET_4_Folder= %WinDir%"\Microsoft.NET\Framework\v4.0.30319"
%_NET_4_Folder%\regasm.exe /unregister %WorkFolder%\Miler.ExcelAddin.dll /Codebase /tlb:%WorkFolder%\Miler.ExcelAddin.tlb >> C:\temp\log.txt
回答1:
Heat.exe
UPDATE: I didn't like what I suggest below (custom action use), and Bob Arnson (WiX coder) reminded me that heat.exe (WiX's general purpose "harvester" / XML markup generator tool) might do the job:
heat.exe file MyLib.dll -sfrag -suid -ag -out ComInterop.wxs
If this works - which you should test - you have removed a whole lot of "clunk" from your WiX installer.
You need to slipstream the generated COM / registry information into the component hosting your COM Interop file in your main WiX source file. This requires some care and precision and is not quite trivial, but you avoid a lot of clunky custom action risk.
You can also heat.exe the tlb file:
heat file MyFile.tlb -sfrag -suid -ag -out ComInterop2.wxs
It seems interface information is skipped by heat.exe
.
Batch Files Considered Harmful
With all due respect, and with the intent to try to be helpful: batch files can be extremely error prone for deployment. They feature almost no error control or ability to handle unexpected conditions. I consider them undesirable for modern deployment and I think it is a consensus opinion.
You should be able to call regasm.exe
directly via an EXE custom action - eliminating all batch file-clunk and complexity. For the record: I don't like EXE CAs either though.
Enough opinions. Here is a basic mock-up example of EXE CAs for insertion into a full-blown WiX source (What characters do I need to escape in XML documents?):
<..>
<!-- AppSearch to find regasm.exe -->
<Property Id="REGASM4" Secure="yes">
<DirectorySearch Id="RegAsmPathx86" Path="[WindowsFolder]Microsoft.NET\Framework\v4.0.30319">
<FileSearch Name="regasm.exe" />
</DirectorySearch>
</Property>
<..>
<!-- Run regasm.exe CAs -->
<CustomAction Id="Install" Directory="SystemFolder"
ExeCommand=""[REGASM4]" "[MyAPP]ClassLib.dll" /Codebase /silent /tlb:"[MyAPP]ClassLib.tlb""
Execute="deferred" Impersonate="no" />
<CustomAction Id="Uninstall" Directory="SystemFolder"
ExeCommand=""[REGASM4]" /unregister "[MyAPP]ClassLib.dll" /Codebase /silent /tlb:"[MyAPP]ClassLib.tlb""
Execute="deferred" Impersonate="no" />
<..>
<!-- Sequenced And Conditioned CAs -->
<InstallExecuteSequence>
<Custom Action="Install" After="InstallFiles">Not Installed</Custom>
<Custom Action="Uninstall" Before="RemoveFiles">REMOVE~="ALL"</Custom>
</InstallExecuteSequence>
回答2:
After researching and trying many different atrributes, I found a solution to my problem. So I'm posting it here may it help someone else. I was finding that my batch file was being deleted before I could run the addin uninstall process, as Brian Sutherland eluded to. I finally found the following code executed at a time in the uninstall that was before the removal of all the files.
<InstallExecuteSequence>
<Custom Action="unregisteraddinpostinstall" After="InstallInitialize">REMOVE="ALL"</Custom>
</InstallExecuteSequence>
So I will still be using the above code, but I am going to implement Stein Asmul's suggestions to clean up my process and not use a batch file. The reason I am still using After="InstallInitialize"
is my ExcelAddin.dll is also part of the regasm.exe /unregister
process to remove Type Class Libraries. It too was being deleted before I could run the script. After I implemented After="InstallInitialize">REMOVE="ALL", the script is working as expected. Thanks again to Brian and Stein!
来源:https://stackoverflow.com/questions/51050861/batch-file-is-not-executing-before-application-uninstalled-using-wix