MessageBox(g_hWndMain, _T("OK to open device!"), _T("Ok"), MB_OK);
// Get list of adapter names
if (!DeviceIoControl(hFile, IOCTL_NDIS_GET_ADAPTER_NAMES, NULL, 0, adName, MAX_PATH, &bytes, NULL))
{
MessageBox(g_hWndMain, _T("FAIL to get Adapter Name!"), _T("Error"), MB_OK);
break;
}
MessageBox(g_hWndMain, _T("OK to get Adapter Name!"), adName, MB_OK);
//打开注册表对网卡IP信息对应子健进行修改
if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE,keyName,0,KEY_WRITE,&hkey))
{
MessageBox(g_hWndMain, TEXT("FAIL to open regestry!"), _T("Error"), MB_OK);
break;
}
MessageBox(g_hWndMain, TEXT("OK to open regestry!"), _T("Ok"), MB_OK);
value = 0;
// set DHCP
if(ERROR_SUCCESS != RegSetValueEx(hkey,TEXT("EnableDHCP"),0,REG_DWORD,(const unsigned char*)&value,sizeof(DWORD)))
MessageBox(g_hWndMain, TEXT("FAIL to set DHCP!"), _T("Error"), MB_OK); // 关闭自动获得IP错误
// set ip address
if(ERROR_SUCCESS != RegSetValueEx(hkey,TEXT("IpAddress"),0,REG_MULTI_SZ,(const unsigned char*)ipaddress, wcslen(ipaddress)*sizeof(TCHAR)+sizeof(TCHAR)))
MessageBox(g_hWndMain, TEXT("FAIL to set IP Address"), _T("Error"), MB_OK); // 设置IP错误
// set subnet mask
if(ERROR_SUCCESS != RegSetValueEx(hkey,TEXT("SubnetMask"),0,REG_MULTI_SZ,(const unsigned char*)subnetmask, wcslen(subnetmask)*sizeof(TCHAR)+sizeof(TCHAR)))
MessageBox(g_hWndMain, TEXT("FAIL to set Subnet Mask!"), _T("Error"), MB_OK); // 设置子网掩码错误
// set gateway
if(ERROR_SUCCESS != RegSetValueEx(hkey,TEXT("DefaultGateway"),0,REG_MULTI_SZ,(const unsigned char*)gateway, wcslen(gateway)*sizeof(TCHAR)+sizeof(TCHAR)))
MessageBox(g_hWndMain, TEXT("FAIL to set Gateway!"), _T("Error"), MB_OK); // 设置网关错误