3

Suppose I've got three UNC paths:

\\it\may\be\samba\on\linux.txt
\\maybe\its\on\windows\fileserver.txt
\\and\that\one\is\dfs.txt

How can I check (in c#) which one is a dfs mapping and which one isn't?

takrl
  • 6,356
  • 3
  • 60
  • 69
  • According to [this](http://en.wikipedia.org/wiki/Distributed_File_System_(Microsoft)), you would need to check if the first part (after the `\\\`) is a domain or a server. That however, would require to do a lookup of some sort, which takes time and should be done asynchronously (depending on the nature of your app). Why do you need to know the difference in the first place? It shouldn't matter to your app. – Christian.K Nov 26 '12 at 12:09
  • @Christian.K I'm using [NetFileEnum](http://msdn.microsoft.com/en-us/library/windows/desktop/bb525378.aspx) to check who has a file open. If it's on dfs I first need to find the target file server holding this file to modify the UNC path accordingly for NetFileEnum to work. [NetDfsGetInfo](http://stackoverflow.com/a/13564613/520044) seems to work for that, but it's slow to return for non-dfs paths. – takrl Nov 26 '12 at 12:16

1 Answers1

3

Found a solution, but it has a drawback. A call to NetDfsGetInfo will return information on the dfs root (or link) if I pass in a dfs root (or link). If it's an UNC path not on dfs it'll return an error.

The only drawback is that returning that error takes about one second, returning dfs info produces an instant result.

If anyone wants to use this solution:
The docs on NetDfsGetInfo say that YOU MUST call NetApiBufferFree on the buffer returned, even if you get an error back.

takrl
  • 6,356
  • 3
  • 60
  • 69
  • 1
    I'd *LOVE* to see the code you created for this. I'm hoping I'll be able to convert it to work in VBS, but getting it would be great. – Lizz Jan 25 '13 at 07:27
  • @takrl - Any alternative of NetDfsGetInfo ? This call is too costly and in environments with large user base takes a long time. – harshit Jan 13 '14 at 09:46
  • @user1043981 I don't know any better ... that's what I found out myself after not getting any answers to this question. If you've got any other ideas, please post ... – takrl Jan 14 '14 at 07:12
  • @takrl thanks for the C# code! Any idea how to do the same in VBS? – Lizz Apr 20 '14 at 03:52
  • Did you ever check to see if one of the other functions such as [NetDFSGetClientInfo](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/api/lmdfs/nf-lmdfs-netdfsgetclientinfo) is any faster? – Spencer Aug 03 '18 at 13:13