Detecting if .exe is running from non-local storage
Detecting if .exe is running from non-local storage
What is the recommended method for detecting that a Delphi .exe file is started from a remote network share?
I'd like to raise a warning to the user and request him to copy the file locally before using it.
What is the recommended method for detecting that a Delphi .exe file is started from a remote network share?
I'd like to raise a warning to the user and request him to copy the file locally before using it.
Check the Application.ExeName or ParamStr(0) if it starts with \\
ReplyDeleteI wonder if you can tell from command line, just a thought, I'm also curios
ReplyDeleteOn Windows I use the API function "GetDriveType", with my executable path, which can return the values: (DRIVE_REMOVABLE, DRIVE_FIXED, DRIVE_REMOTE, DRIVE_CDROM, DRIVE_RAMDISK). If it is a local harddrive, it returns DRIVE_FIXED.
ReplyDeleteGetDriveType seems like the best option, but I guess I have to check that it isn't a local URL as well, as \\localmachine\c$\bin\my.exe would be valid, but I think GetDriveType will report this as Drive_Remote.
ReplyDeleteIf you map a local folder as a network drive, it will still be reported as being remote.
ReplyDeleteExactly - so I need to do additional checking to verify that the "remote path" actually is remote, and not a local reference. Testing what I can get from GetVolumePathName now.
ReplyDeleteGetVolumePathName:
ReplyDelete\\servername\share\filename gives \\servername\share
mapping X: to gives \\servername\share gives X:\
Now - how do I get X:'s actual URL?
WNetGetUniversalName doesn't give me anything :/
Can you build your EXE with IMAGE_FILE_NET_RUN_FROM_SWAP? Then (theoretically) there's no reason to copy it - it will be copied and cached locally by the system. Note that you need the same flag in all PE files used by the program, ie all DLLs and BPLs it uses too.
ReplyDeleteWell, the reason I want it to be copied, and deny running from the share, is that the net share is for retrieving the latest version. When someone runs from the share, I can't even rename the .exe to force a replace of it.
ReplyDeleteBut, there is always those fumblefinger people which keep making shortcuts from the share, instead of from the local copy.
It is a temporary problem as we are moving the .exe upgrade mechanism into db replicated files this fall, but it is an annoying problem.
Ah, fair enough. I was hoping I could solve your problem through something inbuilt without you having to write any code at all. The best code is no code :p
ReplyDeleteDavid Millington - Absolutely! - Alternatively, code you can reuse :)
ReplyDeleteCouldn't you simply remove the read-execute flag from the security settings of the folder? You would miss that warning, though.
ReplyDeleteUwe Raabe - Not easily. There are a multitude of things shared and a multitude of shares. Inherited designs...
ReplyDeleteI'm not sure folder redirects will get you the right volume type.
ReplyDeleteJeroen Wiert Pluimers - GetDriveType will indicate anything that looks "mounted" as remote. My current challenge is to map drive name to share to see if I find the update server in the URL.
ReplyDeleteFYI: WGetNetConnection gave me what I needed to check if a drive was mapped remotely.
ReplyDeleteRudimentary function to check if running from network drive:
http://pastebin.com/WW3gcbRq