SHARE
TWEET

How to figure out if .exe was started from network drive

LarsFosdal Jul 7th, 2015 (edited) 302 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function IsRunningFromNetwork(const ServerName:String = 'BetYouCantFindThisServer'): Boolean;
  2. const
  3.  pMax = 2047;
  4. var
  5.   dt: UINT;
  6.   volpath: Array[0..pMax] of Char;
  7.   sVol: String;
  8.   sz: Cardinal;
  9. begin
  10.   Result := False;
  11.   dt := GetDriveType(PChar(ExtractFilePath(ParamStr(0))));
  12.   if dt = 4
  13.   then begin
  14.     GetVolumePathNameW(PChar(LowerCase(ParamStr(0))), volpath, pMax);
  15.     sVol := StrPas(volpath);
  16.     if not ((pos(LowerCase(ServerName), sVol) <> 0) or (pos('\\', sVol) = 1))
  17.     then begin
  18.       if pos(':', sVol) <> 0
  19.       then begin
  20.         sz := pMax;
  21.         if WNetGetConnection(pChar(Copy(sVol, 1, 2)), volPath, sz) = NO_ERROR
  22.          then Result := (pos(LowerCase(ServerName), LowerCase(StrPas(volPath))) <> 0) or (pos('\\', StrPas(volPath)) = 1);
  23.       end;
  24.     end
  25.     else Result := True;
  26.   end;
  27. end;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top