简体   繁体   English

如何通过自定义卸载操作获取安装目录(由MSI安装,由VS2010创建)?

[英]How to get the installation directory (installed with MSI, created with VS2010) at a custom uninstall action?

So I've created a simple msi-setup for my application using a setup project and added a couple of custom actions that take care of stuff like extracting files from archives. 因此,我使用安装项目为我的应用程序创建了一个简单的msi安装程序,并添加了一些自定义操作,这些操作可以处理诸如从存档中提取文件之类的事情。 Now, there are two extra files in my program files -directory which means that the MSI won't remove the directory at the uninstall by itself. 现在,我的程序文件中有两个额外的文件-目录,这意味着MSI不会在卸载时自行删除该目录。 My solution to this was to create a custom action that removes the rest of the files. 我对此的解决方案是创建一个自定义操作,以删除其余文件。

Now this works just fine and dandy, as long as the default directory is used at installation. 现在,只要在安装时使用默认目录,它就可以正常工作了。 But what if the user chooses to change it? 但是,如果用户选择更改它怎么办? I'd assume there has to be a very simple way to read the directory at the custom action, but I'm not quite sure what that is. 我认为在自定义操作中必须有一种非常简单的方法来读取目录,但是我不确定这是什么。

As far as I've found out by googling, there are properties such as TARGETDIR related to the MSI-package. 据我通过谷歌搜索发现,存在与MSI软件包相关的属性,例如TARGETDIR。 However, some sites also say that I should be setting this property by myself, at the installation stage. 但是,有些站点还说我应该在安装阶段自行设置此属性。

All this has left me quite confused. 这一切使我很困惑。 Basically I see two ways to resolve this: 基本上,我看到两种解决方法:

1) Make sure the application does not create files by itself, and the MSI will take care of it. 1)确保应用程序不会自行创建文件,MSI会照顾好它。 This would mean a bit more work because I'm not responsible for those extra files. 这将意味着更多的工作,因为我不负责这些额外的文件。

2) Find out the installation directory at the custom action while uninstalling the application, and remove the last bits by myself. 2)在卸载应用程序时,在自定义操作中找到安装目录,然后自己删除最后几位。 This is the quick-and-dirty way as I see it, and would definitely suffice for now. 正如我所见,这是一种快速而又肮脏的方式,现在肯定足够了。 But how to accomplish this? 但是如何做到这一点?

Also while I'm here I might as well ask this one more related question. 另外,当我在这里时,我不妨再问一个相关的问题。 As I mentioned earlier, I extract some files at the install. 如前所述,我在安装时提取了一些文件。 Now, I'd like to get rid of these archives once I've extracted them. 现在,一旦我提取了它们,我想摆脱它们。 The problem is, if I do this, MSI will think my installation is broken and copy them back each time I launch the application. 问题是,如果我这样做,MSI会认为我的安装已损坏,并在每次启动该应用程序时将其复制回去。 So how to avoid this? 那么如何避免这种情况呢?

There is no need to use a custom action to remove the files. 无需使用自定义操作即可删除文件。 MSI has built in support for this scenario in two steps: MSI通过以下两个步骤对这种情况进行了内置支持:

  1. Use a search to locate the files you want to remove. 使用搜索找到要删除的文件。 Here is a tutorial http://msdn.microsoft.com/en-us/library/aa371564(VS.85).aspx 这是一个教程http://msdn.microsoft.com/zh-cn/library/aa371564(VS.85).aspx

  2. Then you can schedule a file removal operation to actually delete the files. 然后,您可以安排文件删除操作以实际删除文件。 http://msdn.microsoft.com/en-us/library/aa371201(VS.85).aspx http://msdn.microsoft.com/zh-CN/library/aa371201(VS.85).aspx

Regarding your second question: 关于第二个问题:

Don't add the archives to the File table. 不要将存档添加到“文件”表中。 Instead create some self extracting archives and use binary custom actions to unpack them. 而是创建一些自解压档案,并使用二进制自定义操作将其解压缩。

http://msdn.microsoft.com/en-us/library/aa368085(VS.85).aspx http://msdn.microsoft.com/zh-CN/library/aa368085(VS.85).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM