Behzad
Behzad

Reputation: 2210

How can I determine whether Remote Desktop is running at a given IP address?

I want to find out which ip can be remote. (remote desktop)

For example, I set a valid IP of my network into an edit box and the program says it can be remote or not.

Upvotes: 4

Views: 3421

Answers (3)

Remko
Remko

Reputation: 7340

It depends on what you are trying to accomplish: do you want to see if the server is up and running from within your network? If so try my Terminal Server Ping Tool. Else you can only check if something is listening on port 3389 eg with Indy.

Upvotes: 0

RRUZ
RRUZ

Reputation: 136441

to determine if an ip address is a remote desktop server you can use WTSEnumerateServers function.

follow these steps

  • enumerate the servers in a network domain using the WTSEnumerateServers function
  • when you get the list of the servers convert the name of each server to an ip address
  • now compare the ip address of each server with the ip to check.

see this sample, wich show how use the WTSEnumerateServers function

uses
  Classes,
  Windows,
  SysUtils;

type
PWTS_SERVER_INFO = ^WTS_SERVER_INFO;
_WTS_SERVER_INFO = packed record
pServerName:LPTSTR;
end;
WTS_SERVER_INFO = _WTS_SERVER_INFO;
WTS_SERVER_INFO_Array  = Array [0..0] of WTS_SERVER_INFO;
PWTS_SERVER_INFO_Array =^WTS_SERVER_INFO_Array;

{$IFDEF UNICODE}
function WTSEnumerateServers( pDomainName: LPTSTR; Reserved: DWORD; Version: DWORD; ppServerInfo: PWTS_SERVER_INFO; pCount: PDWORD):BOOLEAN; stdcall; external 'wtsapi32.dll'  name 'WTSEnumerateServersW';
{$ELSE}
function WTSEnumerateServers( pDomainName: LPTSTR; Reserved: DWORD; Version: DWORD; ppServerInfo: PWTS_SERVER_INFO; pCount: PDWORD):BOOLEAN; stdcall; external 'wtsapi32.dll'  name 'WTSEnumerateServersA';
{$ENDIF}
procedure WTSFreeMemory(pMemory:Pointer);stdcall; external 'wtsapi32.dll' name 'WTSFreeMemory';

procedure GetRemoteDesktopsList(const Domain:PChar;const Servers:TStrings);
var
ppServerInfo : PWTS_SERVER_INFO_Array;//PWTS_SERVER_INFO;
pCount       : DWORD;
i            : integer;
begin
  Servers.Clear;
  ppServerInfo:=nil;
  try
    if WTSEnumerateServers(Domain,0,1,PWTS_SERVER_INFO(@ppServerInfo),@pCount) then
      for i := 0 to pCount - 1 do
        Servers.Add(ppServerInfo^[i].pServerName)
    else
    Raise Exception.Create(SysErrorMessage(GetLastError));
  finally
    if ppServerInfo<>nil then
    WTSFreeMemory(ppServerInfo);
  end;
end;

and then call like this

   Servers:=TStringList.Create;
    try
     GetRemoteDesktops(nil,Servers); //using nil for the current domain.
     //now  process the list and do your stuff

    finally
     Servers.Free;
    end;

Upvotes: 4

Marco van de Voort
Marco van de Voort

Reputation: 26371

Search a Remote Desktop component for Delphi and try to connect.

Upvotes: 0

Related Questions