Skip to content

Instantly share code, notes, and snippets.

@jpluimers
Created September 20, 2015 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jpluimers/a5efd2eaa3b7a13dbd27 to your computer and use it in GitHub Desktop.
Save jpluimers/a5efd2eaa3b7a13dbd27 to your computer and use it in GitHub Desktop.
Lars Fosdal; [Delphi] How to figure out if .exe was started from network drive - via http://pastebin.com/WW3gcbRq and https://plus.google.com/u/0/+LarsFosdal/posts/dh2dkyPyhEj
function IsRunningFromNetwork(const ServerName:String = 'BetYouCantFindThisServer'): Boolean;
const
pMax = 2047;
var
dt: UINT;
volpath: Array[0..pMax] of Char;
sVol: String;
sz: Cardinal;
begin
Result := False;
dt := GetDriveType(PChar(ExtractFilePath(ParamStr(0))));
if dt = 4
then begin
GetVolumePathNameW(PChar(LowerCase(ParamStr(0))), volpath, pMax);
sVol := StrPas(volpath);
if not ((pos(LowerCase(ServerName), sVol) <> 0) or (pos('\\', sVol) = 1))
then begin
if pos(':', sVol) <> 0
then begin
sz := pMax;
if WNetGetConnection(pChar(Copy(sVol, 1, 2)), volPath, sz) = NO_ERROR
then Result := (pos(LowerCase(ServerName), LowerCase(StrPas(volPath))) <> 0) or (pos('\\', StrPas(volPath)) = 1);
end;
end
else Result := True;
end;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment