//判断一个机器的MSSQL是否启动,通过SQL DMO是可以的,但对于没有装MSSQL的客户端来说就没办法,此处用的是连接MSSQL的1433端口,如果端口号不同,可以通过传递端口.
unit Judge_U;
interface
uses
SysUtils, Classes, IdBaseComponent, IdComponent, IdTCPConnection, IdIcmpClient,
IdTCPClient, IdRawBase, IdRawClient;
function JudgePort(AServerName: PChar; APort: Integer): Boolean;
function JudgePing(AServerName: PChar): Boolean;
implementation
function JudgePing(AServerName: PChar): Boolean;//这个是用来PIN计算机的.
var
ICMP: TIdIcmpClient;
begin
ICMP := TIdIcmpClient.Create(nil);
ICMP.ReceiveTimeout := 1000;
ICMP.Host := AServerName;
try
ICMP.Ping;
Result := True;
except
Result := False;
end;
ICMP.Free;
end;
function JudgePort(AServerName: PChar; APort: Integer): Boolean;
var
IdTCPClient1: TIdTCPClient;
begin
IdTCPClient1 := TIdTCPClient.Create(nil);
IdTCPClient1.Host := AServerName;
IdTCPClient1.Port := APort;
try
IdTCPClient1.Connect;
Result := True;
IdTCPClient1.Disconnect;
except
Result := False;
end;
IdTCPClient1.Free;
end;
end.
//有以下已知的BUG.
//1 如果一台计算机上安装了多个实例.
//2 如果不用TCP/ip协议,而用其它的连接方式,比如典型的命名管道,就无法判断.
新闻热点
疑难解答