I need to make a exe that will be started from a Windows server share. As soon as the application is running it should disappear from the servers open files list.
For example I have this simple Delphi source as a test - it compiles to a small 28k exe file that simply waits for user input when invoked. While the application is running it appears on the servers open files list. I already tried PEFlags setting IMAGE_FILE_NET_RUN_FROM_SWAP and IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP:
program RunFromShare;
Uses
Windows;
{$APPTYPE CONSOLE}
{$SetPEFlags IMAGE_FILE_NET_RUN_FROM_SWAP} // no exe file open on network share?
{$SetPEFlags IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP}
begin
WriteLn('Waiting for [Enter] key');
ReadLn;
end.
It seems like IMAGE_FILE_NET_RUN_FROM_SWAP
(or IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP
) tells Windows that it should load the whole EXE into memory (backed by the swap file). This doesn't mean it is copied and then run from the local disk, it just prevents page faults from happening later which cause access to the share (possibly after dismount; see such a case here). Which in turn means, the file on the network share is still open as long as the share is connected and the file running.
MSDN says this about IMAGE_FILE_NET_RUN_FROM_SWAP
:
If Image is on Net, copy and run from the swap file.
I would interpret copy as copy to memory, not as copy to disk.
So if nobody does the job for you just do it yourself: copy your file and run it :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With