资源简介
根据注册表修改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 组态王
相关资源
- E4A无障碍跨程序操作类库(带源码、
- 设备管理系统源码
- 安卓wifi直连app源码
- 我的世界源码(易语言版)
- labview编程软件滤波器以及编写程序设
- 我的界面(visual foxpro)源码
- 易语言:一键cf基址源码
- The Secret Path 3D 3D魔方迷宫[源码][scra
- scratch垃圾分类源码(最终版本).sb
- 安卓QQ6.71协议源码易语言,qq协议源码
- 编译原理实验工具及参考源码(lex&
- E盾偷后台工具源码
- WPF USB 网络 串口 通信软件
- UNIX/LINUX编程实践教程的源码
- B/S 网上订餐系统
- 十以内加减法练习 powerbuilder源码
- 农场开发项目
- 教室管理系统.rar
- OCR源码
- PLC上位机编程软件
- 用foobar2000听google音乐[更新一下]
- 学生信息管理系统源码
- 用VC 编写的仿QQ聊天室程序源代码
- 毕业论文之温度传感器DS18B20(源码
- 可自定义导航网站源码
- 栅栏填充算法源码(VC)
- msp430F149操作红外接收模块源码
- [免费]图像识别c 源码
- 小鸡快跑游戏.
- 周易排盘源码
评论
共有 条评论