我怎样才能得到DFS积极UNC路径编程 [英] How can I get an active UNC Path in DFS programatically

查看:207
本文介绍了我怎样才能得到DFS积极UNC路径编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是编程。

有关〔实施例我有2个服务器股份\\\\ server1 \\ folder中\\\\\\服务器2 \\文件夹\\,它已DFS打开,以便它可以在\\\\ DFS_Server \\文件夹\\来访问,我怎么会知道什么是主动路径当前\\\\ DFS_Server \\文件夹\\是,无论是\\\\ server1 \\ folder中\\\\\\服务器2 \\文件夹\\

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\".

推荐答案

试试这其中,sDFSPath是您要查询的路径和sHostServer是要查询你的WMI的服务器,这可以是任何你所提到的两个服务器以上。你甚至可以让一个更优雅的code,当它第一次出现故障的服务器上,然后查询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

public static ArrayList GetActiveServers(string sDFSPath, string sHostServer)
{
    ArrayList sHostNames = new ArrayList(); 

    ManagementPath oManagementPath = new ManagementPath();
    oManagementPath.Server = sHostServer;
    oManagementPath.NamespacePath = @"root\cimv2";

    oManagementScope = new ManagementScope(oManagementPath);
    oManagementScope.Connect();

    SelectQuery oSelectQuery = new SelectQuery();
    oSelectQuery.QueryString = @"SELECT * FROM Win32_DfsTarget WHERE LinkName LIKE '%" + sDFSPath.Replace("\\", "\\\\") + "%' and State = 1";

    ManagementObjectSearcher oObjectSearcher = new ManagementObjectSearcher(oManagementScope, oSelectQuery);
    ManagementObjectCollection oObjectCollection = oObjectSearcher.Get();

    if (oObjectCollection.Count != 0)
    {
        foreach (ManagementObject oItem in oObjectCollection)
        {
            sHostNames.Add(oItem.Properties["ServerName"].Value.ToString());
        }
    }

    return sHostNames;
}

希望这是有道理的。

Hope it makes sense

这篇关于我怎样才能得到DFS积极UNC路径编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆