Hallo Christian,
ich habe mir im
PSDK die APIs NetFileEnum und NetFileGetInfo angesehen
und im Usenet Codesnippets zusammenkopiert (ich weiß, ich weiß, -Pfui,
aber wie soll ich es sonst lernen?), allerdings gelingt es mir nicht
eine Liste zu erstellen (der Pointer auf "buffer" bleibt leer).
Lt.
PSDK ist der lokale Computer gemeint, wenn user und server NUL sind.
Delphi-Quellcode:
UNIT Unit1;
INTERFACE
USES
Windows,
Messages,
SysUtils,
Variants,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
StdCtrls;
TYPE
TForm1 =
CLASS(TForm)
Button1: TButton;
ListBox1: TListBox;
PROCEDURE Button1Click(Sender: TObject);
PRIVATE
{ Private declarations }
PUBLIC
{ Public declarations }
END;
TYPE
NetAPIStatus = Integer;
FILE_INFO_3 =
RECORD
fi3_id: Integer;
fi3_permissions: Integer;
fi3_num_locks: Integer;
fi3_pathname: PWideChar;
fi3_username: PWideChar
END;
PFILE_INFO_3 = ^FILE_INFO_3;
FUNCTION NetFileEnum(
serverName, basePath, userName: PWideChar;
level: Integer;
VAR bufPtr: PWideChar;
prefmaxlen: Integer;
VAR entriesread, totalentries, resumeHandle: Integer
): NetAPIStatus;
stdcall;
FUNCTION NetApiBufferFree(buffer: Pointer): NetAPIStatus;
stdcall;
VAR
Form1 : TForm1;
CONST
MAX_PREFERRED_LENGTH = -1;
NERR_Success = 0;
IMPLEMENTATION
FUNCTION NetFileEnum;
EXTERNAL '
NETAPI32.DLL';
FUNCTION NetApiBufferFree;
EXTERNAL '
NETAPI32.dLL';
{$R *.dfm}
PROCEDURE ListFiles(
CONST server, user:
STRING; list: TStrings);
VAR
wUser : WideString;
wServer : WideString;
err : Integer;
i, NIL_HANDLE, entriesRead, totalEntries: INTEGER;
buffer : pointer;
info : PFILE_INFO_3;
BEGIN
wUser := user;
wServer := server;
err := NetFileEnum(
NIL,
// PWideChar(wServer),
NIL,
NIL,
// PWideChar(wUser),
3,
PWideChar(buffer),
MAX_PREFERRED_LENGTH,
entriesRead,
totalEntries,
NIL_HANDLE);
IF err = NERR_Success
THEN
TRY
info := PFILE_INFO_3(buffer);
FOR i := 0
TO entriesRead - 1
DO
BEGIN
list.Add(info^.fi3_pathname);
Inc(info)
END
FINALLY
NetAPIBufferFree(buffer)
END
ELSE
RAISE Exception.CreateFmt('
Error %d enumerating files', [err])
END;
PROCEDURE TForm1.Button1Click(Sender: TObject);
BEGIN
ListFiles('
', '
', ListBox1.Items);
END;
END.