unit Unit3;
interface
uses
Windows, SysUtils, Classes ,Dialogs ;
const
NERR_Success = 0;
MAX_PREFERRED_LENGTH = DWORD(-1);
type
NET_API_STATUS = DWORD;
SHARE_INFO_2 =
record
shi2_netname : PWideChar;
shi2_type : DWORD;
shi2_remark : PWideChar;
shi2_permissions : DWORD;
shi2_max_uses : DWORD;
shi2_current_uses: DWORD;
shi2_path : PWideChar;
shi2_passwd : PWideChar;
end;
PSHARE_INFO_2 = ^SHARE_INFO_2;
Procedure EnumNetwork (
var EnumNetworkStringlist :TStringlist;Computername_or_IP:
String);
function NetShareEnum(ServerName : PWideChar;
Level : DWORD;
bufptr : Pointer;
PrefMaxLen : DWORD;
EntriesRead : PDWORD;
TotalEntries : PDWORD;
Resume_Handle: PDWORD):NET_API_STATUS;
stdcall;
external '
NetAPI32.dll'
name '
NetShareEnum';
function NetApiBufferFree(Buffer: Pointer): NET_API_STATUS;
stdcall;
external '
NetAPI32.dll'
name '
NetApiBufferFree';
implementation
Procedure EnumNetwork (
var EnumNetworkStringlist :TStringlist;Computername_or_IP:
String);
const
MAX_PREFERRED_LENGTH = -1;
NERR_SUCCESS = 0;
var
ER : DWORD;
// enries read
TE : DWORD;
// total entries
ResHandle : DWORD;
ShareInfo : PSHARE_INFO_2;
p : pChar;
fResult : NET_API_STATUS;
i : Integer;
share, path :
string;
myWideString : WideString;
myWideCharPtr : PWideChar;
begin
ResHandle := 0;
fResult := NetShareEnum(
nil, 2, @ShareInfo, DWORD(MAX_PREFERRED_LENGTH), @ER, @TE, @ResHandle);
if(fResult <> NERR_SUCCESS)
then
Exit;
p := Pointer(ShareInfo);
for i := 0
to TE - 1
do
begin
share := WideCharToString(PSHARE_INFO_2(p)^.shi2_netname);
path := WideCharToString(PSHARE_INFO_2(p)^.shi2_path);
if path<>'
'
then path:='
, '+path;
EnumNetworkStringlist.Add(share+path);
p := p + SizeOf(SHARE_INFO_2);
end;
NetApiBufferFree(@ShareInfo);
end;
end.