...retrieve UNC Paths?
Author: Thomas Stutz
ExpandUNCFileName returns the full path of the FileName
with the network drive portion in UNC format.
The pathname in the UNC-Format has the format:
\\Servername\sharename
ExpandUNCFileName gibt einen String mit dem vollständigen
Pfadnamen der in FileName übergebenen Datei zurück.
Ein vollständig qualifizierter Pfadname besteht aus der
Laufwerkskomponente des Dateinamens im UNC-Format:
\\Servername\sharename
// Example, Beispiel:
Label1.Caption := ExpandUNCFileName('K:\sharename.tmp'));
{where "K" is a Network Drive.}
{*****************************************************}
{2. Way }
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;
printed from
  www.swissdelphicenter.ch
  developers knowledge base