0

I am working on a service that has special conditions if the two UNC paths given to it reside on the same volume. However I have yet to figure out a way of determining this since the C# DriveInfo class does not work with UNC paths.

EX:

\\server\path_a resides on drive A

\\server\path_b resides on drive B

Is there some way of telling that \\server\path_a and \\server\path_b do not reside on the same drive remotely?

  • AFAIK this not possible – BRAHIM Kamel Dec 13 '13 at 20:45
  • 1
    I agree with @Julie - it's either not possible or not reliable. How would you handle the case when `\\server\path_a` and `\\192.168.12.12\path_a` point to the same folder? – Daniel Gabriel Dec 13 '13 at 20:47
  • You might get close with [Active directory to tell something like this](http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C). Might not be exactly what you want tho. – crthompson Dec 13 '13 at 20:48

2 Answers2

0

In c++ i would use netenum share to get the remote physical path and then check if they are on the same path. You could probably to the same in c#

user1540857
  • 194
  • 1
  • 10
0

Sure you can, but you will need to use PInvoke to call into a WinAPI interface located in the NetAPI32 library. For example:

Depending on your needs you can get the SHARE_INFO_2 struct for the shares by calling NetShareGetInfo, which will give you that info object for the share. Have a look at the struct here. The shi2_path property will give you the local path which contains the drive.

The MSDN documentation states the following about that property:

shi2_path

Pointer to a Unicode string specifying the local path for the shared resource. For disks, shi2_path is the path being shared.

Please Note: You will need to have sufficient credentials to get the SHARE_INFO_2 object.

Then when you get both paths you can do something like (very rudimentary):

bool isDriveEqual = sharePath1[0] == sharePath2[0];
Community
  • 1
  • 1
IsakBosman
  • 1,453
  • 12
  • 19