本文介绍了如何指向“网络连接”使用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.

推荐答案


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.


            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#中的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 16:24