if GetSystemMetrics(SM_NETWORK) AND $01 = $01 then ShowMessage('Machine is attached to network') else ShowMessage('Machine is not attached to network' 试试这个吧 我在别处看到的
rhinoceros(犀牛)老兄,我试了一下你的方法,不行呀,不管什么状态都是'Machine is attached to network'
检测计算机是否联网比较简单的做法可以通过一个 Win32 Internet(WinInet) 函数 InternetCheckConnection来实现; 这个函数的功能是检查是否能够建立 Internet 连接。 它的实现是在 %SystemRoot%\System32\wininet.dll 中,Delphi 调用声明在 WinInet.pas 中, 其 API 声明如下:BOOL InternetCheckConnection( IN LPCSTR lpszUrl, IN DWORD dwFlags, IN DWORD dwReserved ); // Uses WinInet; procedure TForm1.Button1Click(Sender: TObject); begin if InternetCheckConnection('http://www.yahoo.com/', 1, 0) then edit1.text:= 'Connected' else edit1.text:= 'Disconnected'; end;
在局域网的公用目录上建一个空的文本文件如cc.txt; 然后通过 if FILEEXISTS('\\服务器名\路径\cc.txt')then showmessage('网络已联接'); else showmessage('网络未联');土办法,我就是这么用的。
if GetSystemMetrics(SM_NETWORK) and $01=$01 then Showmessage('计算机已经连在网络上') else Showmessage('计算机没有连在网络上');
RAS是指拨号连接。
至于本地连接的状态怎么判断,我就不知道了呀!:(
ShowMessage('Machine is attached to network') else
ShowMessage('Machine is not attached to network'
试试这个吧
我在别处看到的
这个函数的功能是检查是否能够建立 Internet 连接。
它的实现是在 %SystemRoot%\System32\wininet.dll 中,Delphi 调用声明在 WinInet.pas 中,
其 API 声明如下:BOOL InternetCheckConnection(
IN LPCSTR lpszUrl,
IN DWORD dwFlags,
IN DWORD dwReserved
);
//
Uses WinInet;
procedure TForm1.Button1Click(Sender: TObject);
begin
if InternetCheckConnection('http://www.yahoo.com/', 1, 0) then
edit1.text:= 'Connected'
else
edit1.text:= 'Disconnected';
end;
然后通过
if FILEEXISTS('\\服务器名\路径\cc.txt')then
showmessage('网络已联接');
else
showmessage('网络未联');土办法,我就是这么用的。
Showmessage('计算机已经连在网络上')
else
Showmessage('计算机没有连在网络上');