使用 WMI 和 C# 检测机器是否在线或离线
我使用vs2008,winxp,在局域网中使用Win2003服务器。
我想要在winxp中安装一个应用程序来检测win2003机器是否在线或离线,以及启动时是否离线。
我有这个参考资料,还有更多参考资料、代码示例和最佳实践吗?
http://danielvl.blogspot.com/2004 /06/how-to-ping-in-c-using.html
http://snipplr.com/view/2157/ping-using-wmi-pingstatus/
http://dotnoted.wordpress.com/2005/01/15/the-popular-c-ping-utility/
I use vs2008, winxp, in LAN network with Win2003 servers.
I want a application installed in winxp for detect if win2003 machines is online or offline , and if offline when boot it.
I have this references, any more references, code samples and best practices ??
http://danielvl.blogspot.com/2004/06/how-to-ping-in-c-using.html
http://snipplr.com/view/2157/ping-using-wmi-pingstatus/
http://dotnoted.wordpress.com/2005/01/15/the-popular-c-ping-utitility/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会选择 .NET
System.Net.NetworkInformation.Ping
,因为它非常灵活,您可以异步执行它,而且我发现它比 WMI 更直观(我已经使用过和仅当我需要从远程计算机获取更多信息而不仅仅是 ping 时才使用 WMI)。但这只是个人意见。I would go for the .NET
System.Net.NetworkInformation.Ping
, because it is quite flexible, you have the possibility of doing it asynchronously and I find it more intuitive than WMI (I have used both and use WMI only if I need to get more info from the remote machine than just the ping). But this is just a personal opinion.如果计算机接受 ICMP 回显请求,则可以使用 Ping 类而不是 WMI。
If the machines honor ICMP echo requests, you can use the Ping class instead of WMI.
不确定问题到底是什么,但就其价值而言,我有一个测试框架,可以在虚拟机上运行测试并需要重新启动它们。重新启动盒子(通过 WMI)后,我等待 ping 失败,然后等待 ping 成功(使用 System.Net.NetworkInformation.Ping 正如其他人提到的),然后我需要等待 Windows 准备就绪:
这有点天真,但它确实有效:)
Not sure exactly what the question is for, but for what it's worth, I have a test framework that runs tests on VMs and needs to reboot them. After rebooting the box (via WMI) I wait for a ping fail, then a ping success (using
System.Net.NetworkInformation.Ping
as mentioned by others) then I need to wait until Windows is ready:It's a little naive, but it works :)