如何指向“网络连接”使用shell32 windows 10在C#中的文件夹 [英] How to pointing to "network connections" folder in C# using shell32 windows 10

查看:90
本文介绍了如何指向“网络连接”使用shell32 windows 10在C#中的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我使用以下代码指向网络连接,旨在根据请求启用和禁用本地连接代码。但后来我意识到它适用于XP,我不知道如何为Windows 7或Windows 10做到这一点,因为与XP相比,文件夹结构不同。请指导我。



Hi,

I am using the following code to point to the Network Connection , aiming to enable and disable the "Local Area Connection" by code up on request. But then i realized that it would work for the XP , i am not sure how to do it for Windows 7 or Windows 10 because of the different folder structure compared to XP. Please guide me.

Shell32.ShellClass sc = new Shell32.ShellClass();
            Shell32.Folder RootFolder = sc.NameSpace(3); // ssfCONTROLS
            Shell32.Folder SrcFlder = null;

            foreach (Shell32.FolderItem2 fi in RootFolder.Items()) {
                if (fi.Name == "Network Connections") {
                    SrcFlder = (Shell32.Folder)fi.GetFolder;
                    return SrcFlder;
                }
            }
            return null;





谢谢,

Ramesh。



我尝试了什么:



我得到的文件夹控制面板中的项目是Java,Nail和Flash Player。没有别的。



Thanks,
Ramesh.

What I have tried:

I get the Folder items in the Control panel are Java, Nail and Flash Player. Nothing else.

推荐答案

如何使用.NET获取计算机中的网络连接列表? [ ^ ]


Hi Grame,



感谢您的回复,



我只能在列表中获得启用的适配器。但我需要的是获得所有,然后我可以启用它我想做的。



Hi Grame ,

Thanks for your reply,

I could get only the enabled adapters in the list. But my need is to get all , and then I could enable it which I wanted to do.

if (e.ProgressPercentage == NETWOEK_ENABLING) {
    m_networkCheckResult.Text = "Enabling Network Adapter";
    m_networkCheckResult.Foreground = Brushes.Yellow;
    NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
    foreach (NetworkInterface adapter in adapters) {
        if ((adapter.Name == "Local Area Connection") || (adapter.Name == "Ethernet")) {
            if (adapter.OperationalStatus != OperationalStatus.Up) {
                System.Diagnostics.ProcessStartInfo psi =
        new System.Diagnostics.ProcessStartInfo("netsh", "interface set interface \"" + adapter.Name + "\" enable");
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo = psi;
                p.Start();
            }
        }
    }
}



谢谢

Ramesh。


Thanks
Ramesh.


您好,感谢您的帮助。



我通过以下方式修复了我的任务,虽然我的目标是禁用和启用网络适配器我在生产过程中测试网络硬件。我使用了WMIC WIN32_networkadapter来完全填充。



Hi Thanks for your help.

I fixed my task by following, Though my aim is to disable and enable network adapter for my testing the network hardware during the production. I used the WMIC WIN32_networkadapter to full fill.

            System.Diagnostics.Process process = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = 
                     new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";

            
                try {
                    startInfo.Arguments = "/c wmic path win32_networkadapter where PhysicalAdapter=True call enable";
                    process.StartInfo = startInfo;
                    process.Start();
                }
                catch (Exception) {
                }

//   You may use the following if wanted specific index. 
//   "/c wmic path win32_networkadapter where index=0 call enable"; // depends on your 
//   adapater's index number.


这篇关于如何指向“网络连接”使用shell32 windows 10在C#中的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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