資源簡介
根據注冊表修改Mac地址,然后將本地連接進行停用和啟用來達到Mac地址的正確修改

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?Microsoft.Win32;
using?Shell32;
using?System.Threading;
using?System.IO;
namespace?WindowsFormsApplication2
{
????public?partial?class?MacModifyForm?:?Tokay.SystemUI.Dialogs.BasicDialog
????{
????????private?const?string?NETWORKADDRESS_KEY?=?@“SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0007“;
????????private?const?string?NETWORKADDRESS_NAME?=?“NetworkAddress“;
????????private?const?string?discVerb?=?“禁用(&B)“;
????????private?const?string?connVerb?=?“啟用(&A)“;
????????private?readonly?string?bufferFile?=?Application.StartupPath?+?“\\buffer.dat“;
????????private?readonly?List?bufferIp?=?new?List();
????????public?MacModifyForm()
????????{
????????????InitializeComponent();
????????????if?(File.Exists(bufferFile))
????????????{
????????????????StreamReader?sr?=?new?StreamReader(bufferFile);
????????????????while?(!sr.EndOfStream)
????????????????{
????????????????????string?line?=?sr.ReadLine();
????????????????????if?(line.Length?>?0)
????????????????????{
????????????????????????bufferIp.Add(line.Trim());
????????????????????}
????????????????}
????????????}
????????}
????????private?void?MacModifyForm_Load(object?sender?EventArgs?e)
????????{
????????????this.textBox1.Text?=?ReadMac();
????????????this.btnOK.Enabled?=?false;
????????}
????????private?string?ReadMac()
????????{
????????????RegistryKey?HKLM?=?Registry.LocalMachine;
????????????try
????????????{
????????????????RegistryKey?Reg?=?HKLM.OpenSubKey(NETWORKADDRESS_KEY);
????????????????object?o?=?Reg.GetValue(NETWORKADDRESS_NAME);
????????????????return?o.ToString();
????????????}
????????????catch
????????????{
????????????????return?string.Empty;
????????????}
????????}
????????private?void?SetMac(string?mac)
????????{
????????????RegistryKey?HKLM?=?Registry.LocalMachine;
????????????RegistryKey?Reg?=?HKLM.OpenSubKey(NETWORKADDRESS_KEY?true);
????????????Reg.SetValue(NETWORKADDRESS_NAME?mac);
????????}
????????private?void?RestartMac()
????????{
????????????this.StopMac();
????????????Thread.Sleep(3000);
????????????this.StartMac();
????????}
????????private?void?StartMac()
????????{
????????????Shell?sh?=?new?Shell32.Shell();
????????????Folder?folder;
????????????Folder?fd;
????????????folder?=?sh.NameSpace(3);
????????????foreach?(FolderItem?myItem?in?folder.Items())
????????????{
????????????????if?(myItem.Name?==?“網絡連接“)
????????????????{
????????????????????fd?=?(Folder)myItem.GetFolder;
????????????????????//禁用網絡
????????????????????foreach?(FolderItem?fi?in?fd.Items())
????????????????????{
????????????????????????foreach?(FolderItemVerb?Fib?in?fi.Verbs())
????????????????????????{
????????????????????????????//啟用網絡
????????????????????????????if?(Fib.Nam
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????7158??2009-02-13?15:45??MacModifyForm.cs
?????文件???????7762??2009-02-13?15:38??MacModifyForm.Designer.cs
?????文件?????978199??2009-02-13?15:38??MacModifyForm.resx
-----------?---------??----------?-----??----
???????????????993119????????????????????3
- 上一篇:數據結構課程設計 文章編輯
- 下一篇:Zigbee cc2530 組態王
評論
共有 條評論