简体   繁体   English

重命名安装程序中的目录

[英]Rename a directory in installer

I am working on a Windows application which needs to be able to update itself. 我正在Windows应用程序上工作,该应用程序需要能够自我更新。 When a button is pressed it starts the installer and then the parent application exits. 当按下按钮时,它将启动安装程序,然后退出父应用程序。 At some point during the installer, the installer attempts to rename the directory that the parent application was running from and fails with "Access Denied" If you run the installer from the desktop it works. 在安装程序过程中的某个时候,安装程序会尝试重命名运行父应用程序的目录,并失败,并显示“访问被拒绝”。如果您从桌面运行安装程序,它将可以正常工作。

I am using CreateProcess to start the installer, is there some way of using this or another API to create the installer completely independantly from the parent application so that it doesn't retain some attachment to the directory. 我正在使用CreateProcess来启动安装程序,是否有某种方法可以使用此程序或其他API完全独立于父应用程序来创建安装程序,因此它不会保留该目录的某些附件。

I'm not convinced that launching the installer separately will solve your issue. 我不认为单独启动安装程序会解决您的问题。 It sounds more like a permissions problem that you might be able to solve using ACL manipulation. 听起来更像是一个权限问题,您可以使用ACL操作来解决。 If the app doesn't already have permissions to mess with that folder, you might be able to write a custom action to remedy the problem by adding the necessary permissions to your process. 如果该应用程序尚无使用该文件夹的权限,则可以通过向流程添加必要的权限来编写自定义操作来解决该问题。

Another way of doing this is to make sure that the directory deletion is happening within a custom action that you control (as in, you own/maintain the code that performs the deletion, rather than rely on MsiExec to do it for you). 这样做的另一种方法是确保目录删除在您控制的自定义操作中发生(例如,您拥有/维护执行删除的代码,而不是依靠MsiExec来为您执行此操作)。 Then, set that custom action to run in the System context so that it will have the same permissions as a service. 然后,将该自定义操作设置为在System上下文中运行,以使其具有与服务相同的权限。 That should provide your installer with sufficient rights to remove the folder. 这应该为您的安装程序提供足够的权限来删除该文件夹。

You should use the normal update system within the windows installer. 您应该在Windows安装程序中使用正常的更新系统。 your access denied message appears because file/directory is in use. 您的访问被拒绝的消息出现,因为文件/目录正在使用中。

renaming directories isn't also not a good idea. 重命名目录也不是一个好主意。 what happened if the user clicks "repair" or "uninstall" ? 如果用户单击“修复”或“卸载”会怎样?

you can start the msi with shellexec. 您可以使用shellexec启动msi。 after that terminate you app immediately. 之后,立即终止您的应用。 you should check that in the msi that your app is NOT running anymore. 您应该在msi中检查您的应用程序是否已不再运行。

do the update. 做更新。 if a file is in use the installer automatically wants to reboot to replace the stuff. 如果正在使用文件,安装程序将自动重新引导以替换文件。

CreateProcess should work if you are passing it the right parameters. 如果传递正确的参数,CreateProcess应该可以工作。 Don't reference the parent process in any way and set most things to NULL. 不要以任何方式引用父进程并将大多数内容设置为NULL。 If that doesn't work, then you can try WinExec(). 如果这不起作用,则可以尝试WinExec()。

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

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