// // Set IP Address, Mask and Gateway // Through the registry entry: // [HKEY_LOCAL_MACHINE/Comm/DM9CE1/Parms/TcpIp] // IpAddress, String // SubnetMask, String // DefaultGateway, String // SYSTEMUTILITY_API BOOL SysUtil_IPConfig(LPCWSTR m_StrIPAddress, LPCWSTR m_StrIPMask, LPCWSTR m_StrGate) { long lResult = 0; HANDLE hIPCEvent = CreateEvent(NULL, TRUE, FALSE, NULL); ; LPCTSTR strSubKeyName = _T("Comm//DM9CE1//Parms//TcpIp"); LPCTSTR strAdapterName = _T("DM9CE1"); LPCTSTR strIP = _T("IpAddress"); LPCTSTR strMask = _T("SubnetMask"); LPCTSTR strGate = _T("DefaultGateway"); LPCTSTR strDHCP = _T("EnableDHCP"); DWORD dwValue = 0; DWORD dwStatus = NotifyAddrChange(&hIPCEvent, NULL); if(dwStatus != NO_ERROR) return FALSE; // Change IP Settings HKEY hKey; DWORD dwStrLen = 0; if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, strSubKeyName, 0, 0, &hKey) == ERROR_SUCCESS) { dwStrLen = wcslen(m_StrIPAddress) * sizeof(WCHAR); lResult = RegSetValueEx(hKey, strIP, 0, REG_SZ, (LPBYTE)m_StrIPAddress, dwStrLen); if(lResult != ERROR_SUCCESS) return FALSE; dwStrLen = wcslen(m_StrIPMask) * sizeof(WCHAR); lResult = RegSetValueEx(hKey, strMask, 0, REG_SZ, (LPBYTE)m_StrIPMask, dwStrLen); if(lResult != ERROR_SUCCESS) return FALSE; dwStrLen = wcslen(m_StrGate) * sizeof(WCHAR); lResult = RegSetValueEx(hKey, strGate, 0, REG_SZ, (LPBYTE)m_StrGate, dwStrLen); if(lResult != ERROR_SUCCESS) return FALSE; dwStrLen = sizeof(dwValue); lResult = RegSetValueEx(hKey, strDHCP, 0, REG_DWORD, (LPBYTE)&dwValue, dwStrLen); if(lResult != ERROR_SUCCESS) return FALSE; RegCloseKey(hKey); } // Rebind NDIS if(!RebindNdisAdapter(strAdapterName)) return FALSE; // Waiting until they are applied if(WaitForSingleObject(hIPCEvent, WAIT_TIMEOUT_10S) != WAIT_OBJECT_0) return FALSE; CloseHandle(hIPCEvent); return TRUE; } 最近项目里用到,放在这里供大家参考。:)