APP_DWORD ChangeIpAddress(APP_LPCHAR lpsInterfaceName,APP_DWORD dwNewdIpAddr,APP_DWORD dwSubnetMask,APP_DWORD dwGatway) { STARTUPINFO si; PROCESS_INFORMATION pi; APP_CHAR szCmdline[2048] = {0}; APP_CHAR szWindowsCardName[2048] = {0}; APP_DWORD dwResult = 0; struct in_addr ip; struct in_addr mask; struct in_addr gateway; int nbWrite = 0; ip.S_un.S_addr = dwNewdIpAddr; mask.S_un.S_addr = dwSubnetMask; gateway.S_un.S_addr = dwGatway; /* Find the adapter name: the one from windows (eg "LOCAL NETOWRK 1") this one can be find from the registry, on XP, VISTA and SEVEN : SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\ */ if(1 != getWindowsAdapterName(lpsInterfaceName, szWindowsCardName)){ return OS_NOT_OK; } nbWrite = sprintf(szCmdline, "netsh interface ip set address name="%s" static ", szWindowsCardName); nbWrite += sprintf(szCmdline + nbWrite, " %s", inet_ntoa( ip)); nbWrite += sprintf(szCmdline + nbWrite, " %s", inet_ntoa( mask)); ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW ; si.wShowWindow = SW_HIDE; ZeroMemory( &pi, sizeof(pi) ); CreateProcess( NULL, szCmdline, NULL, NULL, FALSE, REALTIME_PRIORITY_CLASS , NULL, NULL, &si, &pi); dwWaitIpChange = (APP_DWORD)(pi.hProcess); if(dwWaitIpChange != 0){ WaitForSingleObject( (HANDLE)dwWaitIpChange, INFINITE ); GetExitCodeProcess((HANDLE)dwWaitIpChange, &dwResult); CloseHandle( (HANDLE)dwWaitIpChange ); CloseHandle( pi.hThread ); dwWaitIpChange= 0; if(dwResult != 0){ return OS_NOT_OK; }else{ return OS_OK; } } return OS_NOT_OK; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question