Determine if 2 UNC paths on the same remote machine are on the same volume

204 views Asked by At

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?

2

There are 2 answers

0
IsakBosman On

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];
0
user1540857 On

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#