WMI为quering主动网络和准连接 [英] WMI for quering active networks and associate connections

查看:214
本文介绍了WMI为quering主动网络和准连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更改网络设置,如在<一个描述href="http://stackoverflow.com/questions/209779/how-can-you-change-network-settings-ip-address-dns-wins-host-name-with-$c$c">this文章。这工作好为止。不过,我还需要知道什么活动的网络完成的更改。

I need to change Network settings like described in this article. That works good so far. However I also need to know on what active network I make the changes.

(为了更好的理解,请打开控制面板\网络和Internet \网络和共享中心。不幸的是所有的图片托管网站被封锁我的公司,所以我不能张贴的截图。)

(For a better understanding please open Control Panel\Network and Internet\ Network and Sharing Center. Unfortunately all picture hosting sites are blocked by my company so I can't post a screenshot.)

我怎么能查询哪些连接,与什么样的网络使用WMI(或其他技术)?

Any help on how I can query what connection is associated with what network with WMI (or other technology)?

更新:
我需要查询远程计算机。

UPDATE:
I need to query a remote machine.

推荐答案

您可以使用 NetworkListManager COM组件,无论是与动态的,如下图所示,或者使用的 Windows API的code包其中包含了所有的COM包装。

You can use the NetworkListManager COM component, either with dynamic as shown below or using the Windows API Code Pack which contains all the COM wrappers.

dynamic networkListManager = Activator.CreateInstance(
     Type.GetTypeFromCLSID(new Guid("{DCB00C01-570F-4A9B-8D69-199FDBA5723B}")));

var connections = networkListManager.GetNetworkConnections();
foreach (var connection in connections)
{
    var network = connection.GetNetwork();
    Console.WriteLine("Network Name: " + network.GetName());
    Console.WriteLine("Network Category " + 
        network.GetCategory()+ " (0 public / 1 private / 2 Authenticated AD)" );

}

PowerShell的:

PowerShell:

$networkType = [Type]::GetTypeFromCLSID('DCB00C01-570F-4A9B-8D69-199FDBA5723B')
$networkListManager = [Activator]::CreateInstance($networkType)

$netWorks = $networkListManager.GetNetworkConnections()

foreach ($network in $netWorks)
{
    $name = $network.GetName()
    $category = $network.GetCategory()

    write-host "Network Name: $name"
    write-host "Network Category: $category"
}

这篇关于WMI为quering主动网络和准连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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