//判斷一個(gè)機(jī)器的MSSQL是否啟動(dòng),通過(guò)SQL DMO是可以的,但對(duì)于沒(méi)有裝MSSQL的客戶端來(lái)說(shuō)就沒(méi)辦法,此處用的是連接MSSQL的1433端口,如果端口號(hào)不同,可以通過(guò)傳遞端口.
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;//這個(gè)是用來(lái)PIN計(jì)算機(jī)的.
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 如果一臺(tái)計(jì)算機(jī)上安裝了多個(gè)實(shí)例.
//2 如果不用TCP/ip協(xié)議,而用其它的連接方式,比如典型的命名管道,就無(wú)法判斷.
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注