コード例 #1
0
 private void toolStripButtonRename_Click(object sender, EventArgs e)
 {
     if (treeViewReg.SelectedNode.Level > 0)
     {
         NetworkInfo networkInfo = (NetworkInfo)treeViewReg.SelectedNode.Tag;
         var         Frm         = new FormRename(networkInfo, new DelegateNetworkInfo(SetNetworkName));
         Frm.ShowDialog();
         FlushList();
     }
 }
コード例 #2
0
        private void SetNetworkName(NetworkInfo networkInfo, string Name)
        {
            RegistryKey Reg    = Registry.LocalMachine;
            var         RegNet = Reg.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\Unmanaged\" + networkInfo.KeyName, true);

            RegNet.SetValue("Description", Name);
            RegNet.SetValue("FirstNetwork", Name);
            RegNet.Close();
            RegNet = Reg.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\" + networkInfo.Guid, true);
            RegNet.SetValue("ProfileName", Name);
            RegNet.Close();
            Reg.Close();
        }
コード例 #3
0
        private void toolStripButtonDel_Click(object sender, EventArgs e)
        {
            int Count = 0;

            for (int i = 0; i < treeViewReg.Nodes[0].Nodes.Count; i++)
            {
                if (treeViewReg.Nodes[0].Nodes[i].Checked)
                {
                    Count++;
                }
            }
            if (Count == 0)
            {
                MessageBox.Show(this, "至少选中一个网络进行删除", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string Msg = "确定要删除选中网络?";

            if (treeViewReg.Nodes[0].Nodes.Count == Count)
            {
                Msg = "确定要全删光一个不留???";
            }
            if (MessageBox.Show(this, Msg, Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                for (int i = 0; i < treeViewReg.Nodes[0].Nodes.Count; i++)
                {
                    if (treeViewReg.Nodes[0].Nodes[i].Checked)
                    {
                        NetworkInfo networkInfo = (NetworkInfo)treeViewReg.Nodes[0].Nodes[i].Tag;
                        RegistryKey Reg         = Registry.LocalMachine;
                        var         RegNet      = Reg.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\Unmanaged\", true);
                        RegNet.DeleteSubKey(networkInfo.KeyName);
                        RegNet.Close();
                        RegNet = Reg.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\", true);
                        RegNet.DeleteSubKey(networkInfo.Guid);
                        RegNet.Close();
                        Reg.Close();
                    }
                }
                FlushList();
            }
        }
コード例 #4
0
        private void FlushList()
        {
            treeViewReg.Nodes.Clear();
            var         NodeRoot     = treeViewReg.Nodes.Add("网络列表");
            RegistryKey Reg          = Registry.LocalMachine;
            var         RegUnmanaged = Reg.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\Unmanaged\", true);
            var         Keys         = RegUnmanaged.GetSubKeyNames();

            for (int i = 0; i < Keys.Length; i++)
            {
                NetworkInfo Info = new NetworkInfo();
                Info.KeyName = Keys[i];
                var RegNetwork = RegUnmanaged.OpenSubKey(Keys[i]);
                Info.Name = RegNetwork.GetValue("Description").ToString();
                Info.Guid = RegNetwork.GetValue("ProfileGuid").ToString();
                var node = NodeRoot.Nodes.Add(Info.Name);
                node.Tag = Info;
            }
            NodeRoot.ExpandAll();
            Reg.Close();
        }