如何以编程方式获取 DFS 中的活动 UNC 路径
给定 DFS 路径,我如何以编程方式知道它当前所在的活动路径是什么。
例如,我有 2 个服务器共享为 "\\Server1\Folder\"
和 "\\Server2\Folder\"
并且它已打开 DFS,因此可以访问它在 "\\DFS_Server\Folder\"
上,我如何知道当前 "\\DFS_Server\Folder\"
打开的活动路径是什么,是否是 “\\Server1\Folder\”
或 “\\Server2\Folder\”
。
Given a DFS path how would I know what is the active path it is currently on programatically.
For exmaple I have 2 Servers shares as "\\Server1\Folder\"
and "\\Server2\Folder\"
and it has DFS turned on so it can be accessed on "\\DFS_Server\Folder\"
, how would I know what is the active path currently "\\DFS_Server\Folder\"
is on, whether it is "\\Server1\Folder\"
or "\\Server2\Folder\"
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我正确理解您的要求,还有一个 API 似乎可以满足您的需要:
像这样使用它:
有关 API 参考,请检查 msdn NetDfsGetInfo,DFS_INFO_3,DFS_STORAGE_INFO 和 NetApiBufferFree。
If I understand your requirement correctly, there's also an API that seems to do what you need:
Use it like this:
For an API reference, check msdn on NetDfsGetInfo, DFS_INFO_3, DFS_STORAGE_INFO and NetApiBufferFree.
尝试一下,其中 sDFSPath 是您要查询的路径,sHostServer 是您要查询 WMI 的服务器,这可以是您上面提到的两个服务器中的任何一个。您甚至可以在第一个服务器上失败时编写更优雅的代码,然后在下一个服务器上查询 WMI
希望它有意义
try this where sDFSPath is the path you want to query and sHostServer is the Server you want to query your WMI, this can be any of the two servers you mentioned above. You can even make a more elegant code when it fails on first server then query WMI on the next servers
Hope it makes sense
谢谢你,你的提示很有用。不过,我使用 NetDfsGetClientInfo 更成功。还意识到解析过程可能是递归的。我最终至少进行了 2 次递归调用来获取实际的物理 UNC 共享,这是我的示例。
我不知道,如何
Thank you, your hints were useful. However I was more successfull with NetDfsGetClientInfo. Also realized that resolving process may be recursive. I ended up with at least 2 recursive calls to get the actual physical UNC share and here is my example.
I don't know, how