1. 读取 直接copy来的 没看呢 我机器是不行 我的两位同学倒是正常获取 挺无语...
2. 修改 由于网卡的MAC是在网卡ROM固定不变(虽然有网卡也是可写的) 所以修改真实的MAC 就变成了不大可能的任务
我这里就抄袭下注册表的修改~ 不知道为什么 为什么修改MAC后就不能上网??? 谁能解释下...
哦....原来是MAC绑定的缘故...学习了...
//-----------------------------------------------------1-代码段---------------------------------------------------------
function MacAddress: string;
var
Lib: Cardinal;
Func: function(GUID: PGUID): Longint; stdcall;
GUID1, GUID2: TGUID;
begin
Result :='';
Lib := LoadLibrary('rpcrt4.dll');
if Lib <> 0 then
begin
if Win32Platform <>VER_PLATFORM_WIN32_NT then
@Func := GetProcAddress(Lib, 'UuidCreate')
else @Func := GetProcAddress(Lib, 'UuidCreateSequential');
if Assigned(Func) then
begin
if (Func(@GUID1) = 0) and
(Func(@GUID2) = 0) and
(GUID1.D4[2] = GUID2.D4[2]) and
(GUID1.D4[3] = GUID2.D4[3]) and
(GUID1.D4[4] = GUID2.D4[4]) and
(GUID1.D4[5] = GUID2.D4[5]) and
(GUID1.D4[6] = GUID2.D4[6]) and
(GUID1.D4[7] = GUID2.D4[7]) then
begin
Result :=
IntToHex(GUID1.D4[2], 2) + '-' +
IntToHex(GUID1.D4[3], 2) + '-' +
IntToHex(GUID1.D4[4], 2) + '-' +
IntToHex(GUID1.D4[5], 2) + '-' +
IntToHex(GUID1.D4[6], 2) + '-' +
IntToHex(GUID1.D4[7], 2);
end;
end;
FreeLibrary(Lib);
end;
end;
//-----------------------------------------------------1-代码段---------------------------------------------------------
//-----------------------------------------------------2-代码段---------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
new_mac:string;
reg:TRegistry;
begin
new_mac:=Edit1.Text;
reg:=TRegistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
reg.OpenKey('SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0001',false);
//反正物理网卡就是0000-000x几个咯 自己看着变呗~~~
reg.WriteString('Network Address',new_mac);
reg.CloseKey;
reg.OpenKey('SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0001\Ndi\params\networkaddress',true);
reg.WriteString('ParamDesc','MAC Address');
reg.WriteString('default',new_mac);
//本来很简单的操作注册表 写成代码 真 恶心了不少 哎...高级语言真的高级么??? 不过倒是工整了不老少...⊙﹏⊙b汗
reg.CloseKey;
reg.Free;
ShowMessage('修改成功! 请重启网卡或计算机后生效!');
end;
//-----------------------------------------------------2-代码段---------------------------------------------------------
我的运行图:
下面是同学运行图: