Fórum Verificar PC na rede #380445
01/07/2010
0
Olá pessoal , estou precisando saber se existe um PC na rede, alguma função que eu indico o nome do PC e ela me retorne true ou false.
Muito obrigado pessoal.
Marcelo
Curtir tópico
+ 0
Responder
Posts
07/07/2010
Marcelo
Vou explicar melhor tenho em um edit e vou colocar o nome de um computador (servidor) e quero verificar se o mesmo exite na rede.
Responder
Gostei + 0
07/07/2010
Wilson Junior
type
TNetWkstaGetInfo = function(servername: PChar; level: Cardinal;
out bufptr: Pointer): Cardinal; stdcall;
TNetApiBufferFree = function(Buffer: Pointer): Cardinal; stdcall;
PWkstaInfo100 = ^TWkstaInfo100;
_WKSTA_INFO_100 = record
wki100_platform_id: DWORD;
wki100_computername: LPWSTR;
wki100_langroup: LPWSTR;
wki100_ver_major: DWORD;
wki100_ver_minor: DWORD;
end;
{$EXTERNALSYM _WKSTA_INFO_100}
TWkstaInfo100 = _WKSTA_INFO_100;
WKSTA_INFO_100 = _WKSTA_INFO_100;
{$EXTERNALSYM WKSTA_INFO_100}
function DSiGetDomainNT: string;
var
ngi: TNetWkstaGetInfo;
nfb: TNetApiBufferFree;
pwi: PWkstaInfo100;
hLib: Cardinal;
begin
hLib := LoadLibrary( 'netapi32.dll' );
if hLib > 0 then
begin
try
@ngi := GetProcAddress( hLib, 'NetWkstaGetInfo' );
if @ngi = nil then
Exit
;
@nfb := GetProcAddress(hLib, 'NetApiBufferFree');
if @nfb = nil then
Exit
;
ngi( nil, 100, Pointer(pwi) );
Result := string( pwi.wki100_langroup );
nfb( pwi );
finally
FreeLibrary( hLib );
end;
end
;
end;
function ExisteComputador(Workgroup, NomePC: string);
var
EnumHandle : THandle;
WorkgroupRS: TNetResource;
Buf: Array[1..500] of TNetResource;
BufSize: Cardinal;
Entries: Cardinal;
Result: DWORD;
begin
Result := False;
Workgroup := Workgroup + #0;
FillChar( WorkgroupRS, SizeOf(WorkgroupRS) , 0 );
With WorkgroupRS do
begin
dwScope := 2;
dwType := 3;
dwDisplayType := 1;
dwUsage := 2;
lpRemoteName := @Workgroup[1];
end;
WNetOpenEnum( RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
@WorkgroupRS,
EnumHandle );
try
Repeat
Entries := 1;
BufSize := SizeOf(Buf);
Result := WNetEnumResource(EnumHandle,Entries,@Buf,BufSize);
if (Result = NO_ERROR) and (Entries = 1) then
begin
if UpperCase(StrPas(Buf[1].lpRemoteName)) = UpperCase(NomePC) then
begin
Result := True;
Exit;
end
;
end
;
Until (Entries <> 1) or (Result <> NO_ERROR);
finally
WNetCloseEnum( EnumHandle );
end;
end;
Espero ter colaborado.
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)