删除当前加载的程序集
我的应用程序附带一个卸载程序。 一切工作正常,除了在完成后我找不到删除 uninstaller.exe 文件的方法。
我尝试将当前程序集 exe 复制到临时目录中,但原始文件的文件句柄仍然被锁定。
有任何想法吗?
In my application comes with an uninstaller.
Everything is working fine, except that I can't find no way to delete the uninstaller.exe file when it's all done.
I tried to copy the current assembly exe into a temp directory, but the file-handle of the original file is still locked.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您将需要 PInvoke 来执行此操作。 MoveFileEx 能够安排删除文件下次重新启动时。
就像是:
You will need to PInvoke to do this. MoveFileEx has the ability to schedule deleting the file on next reboot.
Something like:
如果您发布了一些如何准确复制 uninstaller.exe 并将执行更改为该特定可执行文件的代码,那将会很有趣。
我认为卸载应用程序域将释放文件句柄。
It would be interesting if you posted some code of how you exactly copy the uninstaller.exe and change execution to that specific executable.
I think unloading the application domain will free the file-handle.
您也许可以通过使用程序集的卷影复制,但我还没有尝试过这种情况。
You might be able to achieve what you want by using shadow copying of assemblies, but I haven't tried that for this scenario.
您可以延迟使用“cmd”:
You can use "cmd" with delay: