Solved

detect network (shared) drive using C#

Posted on 2006-10-24
3
1,005 Views
Last Modified: 2010-05-18
How can I determine if a drive is mapped or local, using C#? I am using .NET Framework 1.1 with VS.NET 2003.

thanks
guid
0
Comment
Question by:guidway
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Expert1701 earned 500 total points
ID: 17805617
On version 1.1 of the Framework, you can use:

  static bool IsNetworkDrive(char driveLetter)
  {
    const int NetworkDrive = 4;

    System.Management.ObjectQuery query = new System.Management.ObjectQuery("SELECT * FROM Win32_LogicalDisk");
    System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query);
    System.Management.ManagementObjectCollection drives = searcher.Get();

    foreach (System.Management.ManagementBaseObject drive in drives)
      if (drive.Properties["DeviceID"].Value.ToString()[0] == driveLetter)
        return Convert.ToInt32(drive.Properties["DriveType"].Value) == NetworkDrive;

    throw new ArgumentException();
  }

And when you upgrade to version 2.0:

  static bool IsNetworkDrive(char driveLetter)
  {
    foreach (System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())
      if (drive.ToString()[0] == driveLetter)
        return drive.DriveType == System.IO.DriveType.Network;

    throw new ArgumentException();
  }
0
 
LVL 12

Author Comment

by:guidway
ID: 17812179
Excellent! That's more than I expected, but information I needed ( we are about to upgrade to 2.0).

Increasing to 500.
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17813345
Thank you, guidway!
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question