Click to See Complete Forum and Search --> : Deleting, Moving, Renaming in-use file WITHOUT rebooting?


m0zzie
November 25th, 2008, 05:08 PM
Hi all, I have a problem I'm trying to solve and I can't seem to find the answers I need by googling and searching MSDN.

I have an application of mine (just one .exe) running on a central server PC, which has a network share, allowing a few other networked PC's to access/use it.
I want to move/delete/rename that .exe on the server while it is in-use by the other PC's, however, I can't find a way to use MoveFile or DeleteFile to do so. I am aware that MOVEFILE_DELAY_UNTIL_REBOOT can be used with MoveFileEx, however this is not an option, as the sever PC can not be rebooted!

There is certainly a way to do it manually (removing the network share will allow me to do so), but I'm wondering how I can do it using code? I am also aware that depending what my application is doing, this may cause it to crash out due to it no longer being available. This isn't too much of an issue, as it will instantly be replaced by an updated version of the original .exe.

Any help is much, much appreciated!

Mal Reynolds
November 25th, 2008, 08:30 PM
Just a beforehand: I am not an expert, and these are not likely the most graceful ways of doing this!, however, my first thought is that if you are simply replacing an executable image to update a program, it could be possible to terminate any processes loaded from that image (there are a couple of ways of doing this), then, you can either use TerminateProcess() (not recommended! it does not give the process ANY chance of shutting down gracefully), or, what I think is a better idea: either enumerate top level windows to find it, then send it a WM_CLOSE message, or use the CreateRemoteThread()/ExitProcess() trick to shut down the process(es), then update your executable and you're good to go. if you don't need to delete/move the file immediately, you could spawn a "monitor" thread for the file you wish to act upon that simply polls it's status (or attempts to perform the action), and waits to terminate until the action has been completed successfully, then you're main application can go on it's merry way, while waiting... or similarly, if that is the main applications purpose, just do that in the main application. (logically the latter of the two main ideas will not work if the application you are trying to update is expected to run 24/7, and the first may be a more viable option).
As I made sure to state before, I am no expert, and there are many here who have much more experience than I, so if there are better, easier ways of doing this, or my ideas are flawed, then by all means...
:) hope i could help though

Igor Vartanov
November 27th, 2008, 06:05 AM
I have an application of mine (just one .exe) running on a central server PC, which has a network share, allowing a few other networked PC's to access/use it.Are you sure your desription is correct? The shared .exe may be accessed/used from remote PC, but in this case it is running on that PC but not on a central PC. :)

I want to move/delete/rename that .exe on the server while it is in-use by the other PC's...You should not move or delete the .exe file while it is running. Rename typicaly works fine on NTFS as long as the target file remains in the original folder.

There is certainly a way to do it manually (removing the network share will allow me to do so), ...... and this is certainly wrong way. Sharing an executable must follow some strict rules including a policy of doing updates. And that update certainly has to be done with nice applications' shutdown across the whole network. :)