如何不重启系统更改WINCE的MAC地址
已经往WINCE的注册表写入新的MAC地址,IP地址,接着用DeviceIoControl重启网卡,IP地址已经改变,但是MAC地址需要系统重启后才能生效,请问不重启系统可以使MAC地址生效吗???
DeviceIoControl重启网卡是没有作用的,应该将网卡驱动卸载后重新加载才会有效
//更改注册表 RegSetValueEx(hKey, TEXT("MAC_ADDR_0"), 0, REG_DWORD, (LPBYTE)&dwValue0, sizeof(DWORD)); RegSetValueEx(hKey, TEXT("MAC_ADDR_1"), 0, REG_DWORD, (LPBYTE)&dwValue1, sizeof(DWORD)); RegSetValueEx(hKey, TEXT("MAC_ADDR_2"), 0, REG_DWORD, (LPBYTE)&dwValue2, sizeof(DWORD)); RegSetValueEx(hKey, TEXT("MAC_ADDR_3"), 0, REG_DWORD, (LPBYTE)&dwValue3, sizeof(DWORD)); RegSetValueEx(hKey, TEXT("MAC_ADDR_4"), 0, REG_DWORD, (LPBYTE)&dwValue4, sizeof(DWORD)); RegSetValueEx(hKey, TEXT("MAC_ADDR_5"), 0, REG_DWORD, (LPBYTE)&dwValue5, sizeof(DWORD)); RegFlushKey(hKey) RegCloseKey(hKey); //卸载网卡驱动 BOOL bRes = FALSE; HANDLE hFind = INVALID_HANDLE_VALUE; DEVMGR_DEVICE_INFORMATION devInfo = {0}; devInfo.dwSize = sizeof(devInfo); DeviceSearchType searchType; searchType = DeviceSearchByLegacyName; hFind = FindFirstDevice(searchType,TEXT("NDIS:"),&devInfo); if(hFind == INVALID_HANDLE_VALUE) { return FALSE; }
bRes = DeactivateDevice(devInfo.hDevice);
FindClose(hFind);
//重新加载网卡驱动 DWORD dwParam HANDLE hd = ActivateDeviceEx(TEXT("Drivers\\Builtin\\NDS0"),NULL,0,&dwParam); CloseHandle(hd);
试过这样子写驱动确实是卸载了 不过更改了MAC地址的注册表后 依然没有更新MAC地址!不知道哪里有问题呢,网卡驱动不能动态卸载的吧。 这个估计真要重启系统才生效了。
|