开发者

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.


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;


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜