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.

16 thoughts on “Detecting if .exe is running from non-local storage

  1. 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.

  2. GetDriveType seems like the best option, but I guess I have to check that it isn’t a local URL as well, as \localmachinec$binmy.exe would be valid, but I think GetDriveType will report this as Drive_Remote.

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

  4. GetVolumePathName:

    \servernamesharefilename gives \servernameshare

    mapping X: to gives \servernameshare gives X:

    Now – how do I get X:’s actual URL?

    WNetGetUniversalName doesn’t give me anything :/

  5. 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.

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

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

Leave a Reply