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.

Comments

  1. Check the Application.ExeName or ParamStr(0) if it starts with \\

    ReplyDelete
  2. I wonder if you can tell from command line, just a thought, I'm also curios

    ReplyDelete
  3. On 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.

    ReplyDelete
  4. GetDriveType 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.

    ReplyDelete
  5. If you map a local folder as a network drive, it will still be reported as being remote.

    ReplyDelete
  6. Exactly - 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.

    ReplyDelete
  7. GetVolumePathName:
    \\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 :/

    ReplyDelete
  8. 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.

    ReplyDelete
  9. Well, 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.
    But, 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.

    ReplyDelete
  10. 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

    ReplyDelete
  11. David Millington - Absolutely! - Alternatively, code you can reuse :)

    ReplyDelete
  12. Couldn't you simply remove the read-execute flag from the security settings of the folder? You would miss that warning, though.

    ReplyDelete
  13. Uwe Raabe - Not easily.  There are a multitude of things shared and a multitude of shares.  Inherited designs...

    ReplyDelete
  14. I'm not sure folder redirects will get you the right volume type.

    ReplyDelete
  15. Jeroen 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.

    ReplyDelete
  16. FYI: WGetNetConnection gave me what I needed to check if a drive was mapped remotely.

    Rudimentary function to check if running from network drive:
    http://pastebin.com/WW3gcbRq

    ReplyDelete

Post a Comment