uses
JwaWinType, JwaWinNetWk;
// Jedi Apilib, can also use JwaWindows instead of Single Units
const
WNNC_NET_TERMSRV = $00360000;
type
TNetResourceArray =
array[0..ANYSIZE_ARRAY-1]
of NETRESOURCE;
PNetResourceArray = ^TNetResourceArray;
procedure TForm3.Button1Click(Sender: TObject);
var
NetResPtr: PNetResourceArray;
ProviderName:
array[0..MAX_PATH]
of Char;
BufSize: DWORD;
hEnum: DWORD;
Count: DWORD;
Res: Cardinal;
i: Integer;
begin
// Get Provider Name (should be 'Microsoft Terminal Services')
BufSize := Length(ProviderName) * SizeOf(Char);
ZeroMemory(@ProviderName[0], BufSize);
Res := WNetGetProviderName(WNNC_NET_TERMSRV, ProviderName, BufSize);
if Res <> NO_ERROR
then
begin
// Handle the Error (call WNetGetLastError for more info), raise exception..
end;
Memo1.Lines.Add(Format('
ProviderName=%s', [ProviderName]));
Res := WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_ANY, 0,
nil, hEnum);
if Res = NO_ERROR
then
begin
// return as many entries as possible
Count := DWORD(-1);
// Allocate a some memory, 16 KB is typical size per docs
BufSize := 16384;
Memo1.Lines.Add(Format('
Allocate %d Bytes', [BufSize]));
GetMem(NetResPtr, BufSize);
Res := WNetEnumResource(hEnum, Count, NetResPtr, BufSize);
while Res = ERROR_MORE_DATA
do
begin
Inc(BufSize, SizeOf(NETRESOURCE));
Memo1.Lines.Add(Format('
Allocate %d Bytes', [BufSize]));
ReAllocMem(NetResPtr, BufSize);
// Alloc more...
Count := DWORD(-1);
Res := WNetEnumResource(hEnum, Count, NetResPtr, BufSize);
end;
if Res = NO_ERROR
then
begin
Memo1.Lines.Add(Format('
Count=%d', [Count]));
for i := 0
to Count - 1
do
begin
if lstrcmpi(NetResPtr^[i].lpProvider, @ProviderName[0]) = 0
then
begin
Memo1.Lines.Add(Format('
Found TSClient Drive: %s', [NetResPtr^[i].lpRemoteName]));
end
else begin
Memo1.Lines.Add(Format('
Found non TSClient Drive: %s', [NetResPtr^[i].lpRemoteName]));
end;
end;
end
else begin
Memo1.Lines.Add(Format('
WNetEnumResource returned %d', [Res]));
end;
FreeMem(NetResPtr);
WNetCloseEnum(hEnum);
end
else begin
Memo1.Lines.Add(Format('
WNetOpenEnum returned %d', [Res]));
end;
end;
end.