用于查询活动网络和关联连接的 WMI

发布于 2024-12-02 05:23:14 字数 384 浏览 0 评论 0原文

我需要更改网络设置,如 这篇文章。到目前为止效果很好。但是我还需要知道我在哪个活动网络上进行了更改。

(为了更好地理解,请打开控制面板\网络和Internet\网络和共享中心。不幸的是,所有图片托管网站都被我的公司阻止,所以我无法发布屏幕截图。)

有关如何操作的任何帮助我可以使用 WMI(或其他技术)查询哪个连接与哪个网络关联?

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

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.

(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.)

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧夏天 2024-12-09 05:23:14

您可以使用 NetworkListManager COM 组件,可以使用如下所示的动态组件,也可以使用 Windows API 代码包,其中包含所有 COM 包装器。

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)" );

}

电源外壳:

$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"
}

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:

$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"
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文