Mega Code Archive

 
Categories / Delphi / Examples
 

How to retrieve UNC Paths

Title: How to retrieve UNC Paths function GetUNCName(const LocalPath: string): string; var BufferSize: DWord; DummyBuffer: Byte; Buffer: Pointer; Error: DWord; begin BufferSize := 1; WNetGetUniversalName(PChar(LocalPath), UNIVERSAL_NAME_INFO_LEVEL, @DummyBuffer, BufferSize); Buffer := AllocMem(BufferSize); try Error := WNetGetUniversalName(PChar(LocalPath), UNIVERSAL_NAME_INFO_LEVEL, Buffer, BufferSize); if Error NO_ERROR then begin SetLastError(Error); RaiseLastWin32Error; end; Result := PUniversalNameInfo(Buffer)^.lpUniversalName finally FreeMem(Buffer); end; end; procedure TForm1.Button1Click(Sender: TObject); begin Label1.Caption := GetUNCName('y:\xyz\') end; Usage Example: Label1.Caption := ExpandUNCFileName('K:\sharename.tmp')); {where "K" is a Network Drive.}