我想从C#服务应用程序检查远程Windows 2003文件服务器的可用性. 仅文件共享测试是相关的(ping和其他测试在这里无济于事-即使禁用了文件共享或防火墙可以允许文件传输但拒绝ping,服务器也可以响应ping).我尝试了几种方法,但都不适合我的需求. 我想在没有管理员权限的情况下检查服务器的可用性,并且当服务器实际上不可用时,当共享脱机可用时,我不希望得到积极的回应. 如果共享文件夹脱机可用,即使服务器不可用,System.IO.DirectoryInfo.Exists(\\servername\sharedfolder)也会返回true . P/调用NetShareEnum()具有相同的缺陷". System.Management 命名空间中的WMI函数需要远程服务器上的管理员权限. 任何人都有一个想法如何进行正确的可用性检查?
I want to check availability of a remote Windows 2003 file server from a C# service application. Only file sharing test is relevant (ping and other tests do not help here - a server can respond to ping even when file sharing is disabled or firewall can allow file transfer but deny ping). I have tried several approaches but none suits my needs. I want to check server availability without admin rights and don''t want positive response when share is available offline while server is actualy unavailable. System.IO.DirectoryInfo.Exists(\\servername\sharedfolder) returns true if sharedfolder is available offline, even when server is not available. P/Invoke to NetShareEnum() has the same ''flaw''. WMI functions in System.Management namespace need admin rights on remote server. Anyone has an idea how to do proper availability check?
推荐答案您好, 另一个解决方案是对服务器执行ping操作,如果收到响应,则表明服务器处于联机状态. :) Hello, Another solution is to ping the server, if you get a response the server is online. :) using System.Net.NetworkInformation;
PingReply pingReply; using (var ping = new Ping()) { pingReply = ping.Send("fileservername"); } if (pingReply.Status == IPStatus.Success) { Console.Write("Server is available"); } }
瓦莱里.
Valery.
一些想法: 1.将一个0字节的文件写入共享,然后将其删除. (需要写/删除访问权限) 2. 断开连接,然后重新连接到共享 [ ^ ]. (这将中断所有文件传输). 3.使用方法+检查远程服务器是否在tcp/445上监听 Some ideas: 1. Write a 0 byte file to the share, then delete it. (requires write/delete access) 2. Disconnect then reconnect to the share[^]. (this will break any file transfers). 3. Use your method + check if the remote server is listening on tcp/445
更多推荐
如何检查C#是否可用文件服务器?
发布评论