Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

windows - Getting a custom action to run on install and uninstall

I've experimented with deferred custom action type 18. I've read a lot of material on the internet including this similar question How to add a WiX custom action that happens only on uninstall (via MSI)? which gives a big truth table of properties, but nothing seems to match my experiences with my Wix. I've upgraded to the latest Wix 3.11.

File element is within the directory structure...

<File Id='ReplaceRegistryEntriesFile' Source='MikeyRegistryReset.bat' 
      DiskId='1' 
/>

The rest is under Product...

<InstallExecuteSequence>
<Custom Action="RunOnUninstall"  
        After="InstallInitialize"
> 
</Custom>
</InstallExecuteSequence>

<CustomAction Id="RunOnUninstall" 
    FileKey="ReplaceRegistryEntriesFile"
    ExeCommand=" mabwashere"
    Impersonate="no" Return="asyncNoWait"
    Execute="deferred" 
/>

It's actually causing the script to run during the uninstall phase. Why didn't it run during the installation phase? There is no logic (that could possibly have been placed there explained in the link above) currently there to stop it from running anytime it wants to run. I was expecting it to run during both install and uninstall.

It gets more strange. If I change After="InstallInitialize" to Before="InstallFinalize", my batch file then only runs during installation.

Maybe this is unique to deferred custom actions! So is a deferred custom action only ever run once in the Install/Uninstall cycle? I've seen no documentation to tell me this.

WTF is going on?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Well I've got a version working. I've got two deferred custom actions, one runs Before="RemoveRegistryValues", the other one is After="InstallFiles". They both call the same .bat file, but pass a different argument during install and uninstall (the values INSTALL and UNINSTALL in my case).

Some code...

<InstallExecuteSequence>
<Custom Action="RunOnUninstall"  
        Before="RemoveRegistryValues"
> 
</Custom>
<Custom Action="RunOnInstall"  
        After="InstallFiles"
> 
</Custom>
</InstallExecuteSequence>

<CustomAction Id="RunOnUninstall" 
    FileKey="ReplaceRegistryEntriesFile"
    ExeCommand=" UNINSTALL"
    Impersonate="no" Return="asyncNoWait"
    Execute="deferred" 
/>
<CustomAction Id="RunOnInstall" 
    FileKey="ReplaceRegistryEntriesFile"
    ExeCommand=" INSTALL"
    Impersonate="no" Return="asyncNoWait"
    Execute="deferred" 
/>

There are a couple of problems though I discovered during testing:

Problem 1: The File element is in the directory structure. I was forced to use the file element to run a batch file (with .bat extension) with custom action type 18, and that file element had to be placed in the directory structure causing the file to be installed on the computer. I did some testing, and that file/batch script can be modified after the .msi is installed (with admin privilege albeit), causing the uninstall to possibly not work correctly. I thought that deferred custom actions keep the file in the .msi script and run that. But this is not happening, it's running the batch script that is currently in the file structure during uninstall. If anyone has tips on how to correct this behaviour I'm still willing to hear about it.

Problem 2. When I install the .msi, the registry changes that were performed in the batch script take effect immediately (in this case NeverShowExt was removed), and the missing file extensions show immediately. But when the .msi is uninstalled and the registry entries are replaced, the file extensions still show until I log out and log back in.

Problem 3: Still the same problem as before, this is all undocumented behaviour. Anyone that can point me to some documentation that explains why this is working would be appreciated.

Even with the above problems, I'm actually quite happy I've got my product working. So I'm going to run with it and go on with other things now, until perhaps someone gives me more information addressing the problems I listed above.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...