views:

117

answers:

3

I am working on a Windows application which needs to be able to update itself. 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.

+1  A: 

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. 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). Then, set that custom action to run in the System context so that it will have the same permissions as a service. That should provide your installer with sufficient rights to remove the folder.

Brian
+1  A: 

You should use the normal update system within the windows installer. 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. after that terminate you app immediately. you should check that in the msi that your app is NOT running anymore.

do the update. if a file is in use the installer automatically wants to reboot to replace the stuff.

Bernd Ott
+1  A: 

CreateProcess should work if you are passing it the right parameters. Don't reference the parent process in any way and set most things to NULL. If that doesn't work, then you can try WinExec().

verhogen