Click here to Skip to main content
15,907,281 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
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?
Posted
Updated 28-Nov-11 11:49am
v2

Hello,

Another solution is to ping the server, if you get a response the server is online. :)

C#
using System.Net.NetworkInformation;


C#
PingReply pingReply;
    using (var ping = new Ping())
    {
        pingReply = ping.Send("fileservername");
    }
    if (pingReply.Status == IPStatus.Success)
    {
        Console.Write("Server is available");
    }
}



Valery.
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900