如何得知用户 拔开网线 了?(50分)

我也强烈关注。
 
说来也奇怪,我的机器用的是win2000,就不能探知网线被拔掉,公司的其他机器也是如此,<br>不知什么原因……
 
我是2000 Pro但可以侦测到。(是不是你们单位的2000没打补丁?)
 
楼主 &amp; 无忌兄:<br>我又重新分析测试了。我的代码和 MSN 的检测使用的是同一组代码,各种网络反应毫无差异。<br>这次测试特意对你二人提出的拔网线问题做了调查,这里解释如下(我没有进一步完成):<br>拔掉网线,在 Windows 2000 中马上会跳出一个气泡提示:“网络电缆没有插好”。经查,这是<br>使用系统事件通知 SensEvents 中的 ISensNetwork 接口里的一个 ConnectionLost 方法。要测<br>试这个方法,需要导入 Sens.dll 中的 COM+ 类型库,向系统预约事件通知。由于这方面资料奇<br>少,我没有完成最后的代码编写。抱歉。
 
1.真诚感谢小雨哥的努力。<br>2.小雨哥,你的意思是不是要达到MSN的效果,目前是没有办法了?<br>&nbsp;<br>设想:我们有没办法通过侦测系统托盘(网络状态)的变化来获取呢?
 
小雨哥:可把简单代码给兄弟们一阅吗?
 
其实,我只需要捕捉到用户拔开网线了就可以了。但就是没办法呀。。。。<br>
 
我以前做过一个项目<br>用TSocketConnection作连接的<br>断线后会有My_Msg_SockErr消息 然后就提示 用户 掉线了<br><br>不知有没有帮助<br><br><br>
 
对不起写漏了<br>procedure TFrmmain.ApplicationEvents1Exception(Sender: TObject;<br>&nbsp; E: Exception);<br>var<br>&nbsp; str, strcaption: string;<br>begin<br>&nbsp; if Sender = SocketConnection1 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; postmessage(Handle, My_Msg_SockErr, 0, 0);<br>&nbsp; &nbsp; end<br>
 
简单!!!!!<br>你可以下一个PING控件<br>然后PING一下某的地址(如服务器)。。。。。<br>不就知道了。<br>而且你的目的就是要检查网络通不通吧!
 
有好的方案了。(可惜是VC++的代码)<br>Getting Notified Regarding Internet Connections <br><br>--------------------------------------------------------------------------------<br>This article was contributed by Muhammad Usman Riaz.. <br>Environment: Win95, Win98, WinME, WinNT, Win2K, WinXP <br><br>I have been looking for some time how to get notified when the user <br>connects to Internet just as MSN or Yahoo Messenger starts the login <br>procedure, as soon as the user connects to Internet. At CodeGuru and <br>other discussion forums, the way people suggested was more of a <br>work-around like pinging a server or IP address after some time interval.<br><br>There is a Win32 API, RasConnectionNotification, that I guess applications <br>such as MSN and Yahoo Messenger use to get notified. To use this API, <br>we first need to create an Event Object, using CreateEvent; then we pass <br>the EvenObject created by CreateEvent to RasConnectionNotification <br>(to be signaled by System when Ras Connection is made), and then we <br>wait for the Ras Connection Event to happen using the Wait Function <br>WaitForSingleObject.<br><br>
 
有人问:If Already Connected<br><br>--------------------------------------------------------------------------------<br>Yep i understand in an office enviorment one is normally always connected what i suggest is to use this demo in combination with with another something like ping or RasGetConnectionState API (you can find lots of examples on codeguru for checkinging if user is connected or not) so if ur NOT connected then you can use the demo code to wait for user to get connected as the demo does. So the logical way i think should be <br>if(IsUserConnected()) // can b checked via a ping to an IP. <br>return; // or do something after user connectes <br>else <br>WaitforConnection(); // what the Demo Does <br><br><br>Regards, <br>Usman. <br><br>Submitted By: Usman (2002/08/13) <br><br>
 
回答:<br>Re: If Already Connected<br><br>--------------------------------------------------------------------------------<br>As it was prevoiusly noted you won't get notified this way about <br>already established connection to the Internet. You can retrieve the <br>connected state of the local system using <br>"InternetGetConnectedState(Ex)". <br>It will show you whether the established connection you have is <br>a Dial-Up connection or LAN and whether a client uses a Proxy server or not. <br>Cheers. <br><br>Submitted By: long_double (2003/01/04) <br><br>
 
兄弟看明白了吗?<br>现在贴上代码:<br>如下:
 
不方便贴这里,我上传到www.playicq.com了。<br>在源码-&gt;系统-&gt;网络状态侦测 上。<br>http://www.playicq.com/dispdoc.php?id=2958
 
有功力的兄弟,把它们消化一下。并译成Delphi如何?<br>为了找到它,费了很大的劲。
 
参见另外一贴<br>http://www.microsoft.com/mind/0698/ras/ras.asp<br>
 
楼主:<br>你上面贴的和我前次说的代码是一回事,我写的代码发给你没问题,但游戏分数可不可<br>以加一点呢。:) &nbsp; &nbsp; 反正你还有将近 3000 分的富裕。<br>另外澄清一些你的说法,我将要给你的代码,经我测试,确实和 MSN 使用的函数是一致<br>的,但它依然不能达到张无忌兄提出的要求。如果只是研究 MSN ,问题已经结束,但需<br>要象 Windows 那样知道网络情况,在 Windows 中提供了一些方法,其中被 2000 系统(<br>XP 大概也一样)使用的方法,就是我上面说的“系统通知事件”。我最近突然对函数植入<br>比较感兴趣,所以不能化时间在这个问题上了,有兴趣的朋友,只要使用 Delphi 自带的<br>导入类型库(菜单 Project---&gt;Import Type Library...)导入 SENS Events Type Library<br>就可以看到完整的类型和接口声明( 注意:只在 Windows 2000 以上系统才有 ),然后使<br>用 CoCreateInstance 建立系统事件的 COM 实例,获取相应的接口,等待系统事件的发生。<br>具体每个接口的用法和作用,Delphi 帮助上找不到,需要到 MSDN 上查,新闻组也有讨论。
 
小雨哥:我没有收到你的代码呀?<br>&nbsp; &nbsp; &nbsp; &nbsp; 是不是重新发一下。nzfboy@21cn.com
 
顶部