请指教:如何准确检测计算机已经上网或离线?(17分)

  • 主题发起人 主题发起人 快乐大使
  • 开始时间 开始时间

快乐大使

Unregistered / Unconfirmed
GUEST, unregistred user!
请指教:如何准确检测计算机已经上网或离线?<br>我使用了以下函数进行判断,但当我把网线拔掉仍然返回true,不知是什么原因?请高手指教,是否有其它准确测试的方法呢?<br>function InternetConnected: Boolean;<br>const<br>&nbsp; // local system uses a modem to connect to the Internet.<br>&nbsp; INTERNET_CONNECTION_MODEM &nbsp; &nbsp; &nbsp;= 1;<br>&nbsp; // local system uses a local area network to connect to the Internet.<br>&nbsp; INTERNET_CONNECTION_LAN &nbsp; &nbsp; &nbsp; &nbsp;= 2;<br>&nbsp; // local system uses a proxy server to connect to the Internet.<br>&nbsp; INTERNET_CONNECTION_PROXY &nbsp; &nbsp; &nbsp;= 4;<br>&nbsp; // local system's modem is busy with a non-Internet connection.<br>&nbsp; INTERNET_CONNECTION_MODEM_BUSY = 8;<br>var<br>&nbsp; dwConnectionTypes : DWORD;<br>begin<br>&nbsp; dwConnectionTypes := INTERNET_CONNECTION_MODEM+ INTERNET_CONNECTION_LAN<br>&nbsp; + INTERNET_CONNECTION_PROXY;<br>&nbsp; Result := InternetGetConnectedState(@dwConnectionTypes, 0);<br>end;<br>
 
以上代码在98行不通,要用RAS。
 
能具体的介绍一下吗?我现在是倾我所有呀,分不多,但心可是诚啊!若能给出代码我将感恩不尽呀!
 
procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; if GetSystemMetrics(SM_NETWORK) AND $01 = $01 then<br>&nbsp; &nbsp; ShowMessage('Machine is attached to network') else<br>&nbsp; &nbsp; ShowMessage('Machine is not attached to network');<br>end;<br><br>葵花宝典上的。。
 
这个可以:<br>function InternetConnected: Boolean;<br>const<br>MaxConnections = 10;//最多的拨号连接数目<br>var<br>connections : array[0..MaxConnections-1] of tRASCONN;<br>longSize : dword;<br>intAvailabelConnections : dword;<br>begin<br>connections[ 0 ].dwSize := sizeof(tRASCONN);//结构的大小<br>longSize := MaxConnections * connections[ 0 ].dwSize;//缓冲区大小<br>intAvailabelConnections := 0;//实际的活动连接的数目<br>//获取当前系统中活动的连接<br>RasEnumConnectionsa( @connections[ 0 ], @longSize,@intAvailabelConnections );<br>Result := intAvailabelConnections&gt;0;<br>END;<br>
 
后退
顶部