Changeset 19160 in vbox for trunk/src/VBox/Main/win
- Timestamp:
- Apr 24, 2009 9:04:38 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/win/NetIf-win.cpp
r19130 r19160 65 65 66 66 #define VBOX_APP_NAME L"VirtualBox" 67 68 static HRESULT netIfWinIsHostOnly(IWbemClassObject * pAdapterConfig, BOOL * pbIsHostOnly)69 {70 VARIANT vtServiceName;71 BOOL bIsHostOnly = FALSE;72 VariantInit(&vtServiceName);73 74 HRESULT hr = pAdapterConfig->Get(L"ServiceName", 0, &vtServiceName, 0, 0);75 if(SUCCEEDED(hr))76 {77 *pbIsHostOnly = !Bstr(vtServiceName.bstrVal).compare(Bstr("VBoxNetAdp"));78 79 VariantClear(&vtServiceName);80 }81 82 return hr;83 }84 85 static HRESULT netIfWinCreateIWbemServices(IWbemServices ** ppSvc)86 {87 HRESULT hres;88 89 // Step 3: ---------------------------------------------------90 // Obtain the initial locator to WMI -------------------------91 92 IWbemLocator *pLoc = NULL;93 94 hres = CoCreateInstance(95 CLSID_WbemLocator,96 0,97 CLSCTX_INPROC_SERVER,98 IID_IWbemLocator, (LPVOID *) &pLoc);99 if(SUCCEEDED(hres))100 {101 // Step 4: -----------------------------------------------------102 // Connect to WMI through the IWbemLocator::ConnectServer method103 104 IWbemServices *pSvc = NULL;105 106 // Connect to the root\cimv2 namespace with107 // the current user and obtain pointer pSvc108 // to make IWbemServices calls.109 hres = pLoc->ConnectServer(110 _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace111 NULL, // User name. NULL = current user112 NULL, // User password. NULL = current113 0, // Locale. NULL indicates current114 NULL, // Security flags.115 0, // Authority (e.g. Kerberos)116 0, // Context object117 &pSvc // pointer to IWbemServices proxy118 );119 if(SUCCEEDED(hres))120 {121 LogRel(("Connected to ROOT\\CIMV2 WMI namespace\n"));122 123 // Step 5: --------------------------------------------------124 // Set security levels on the proxy -------------------------125 126 hres = CoSetProxyBlanket(127 pSvc, // Indicates the proxy to set128 RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx129 RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx130 NULL, // Server principal name131 RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx132 RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx133 NULL, // client identity134 EOAC_NONE // proxy capabilities135 );136 if(SUCCEEDED(hres))137 {138 *ppSvc = pSvc;139 /* do not need it any more */140 pLoc->Release();141 return hres;142 }143 else144 {145 LogRel(("Could not set proxy blanket. Error code = 0x%x\n", hres));146 }147 148 pSvc->Release();149 }150 else151 {152 LogRel(("Could not connect. Error code = 0x%x\n", hres));153 }154 155 pLoc->Release();156 }157 else158 {159 LogRel(("Failed to create IWbemLocator object. Err code = 0x%x\n", hres));160 // CoUninitialize();161 }162 163 return hres;164 }165 166 static HRESULT netIfWinFindAdapterClassById(IWbemServices * pSvc, const Guid &guid, IWbemClassObject **pAdapterConfig)167 {168 HRESULT hres;169 WCHAR aQueryString[256];170 // char uuidStr[RTUUID_STR_LENGTH];171 // int rc = RTUuidToStr(guid.toString().raw(), uuidStr, sizeof(uuidStr));172 {173 swprintf(aQueryString, L"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE SettingID = \"{%S}\"", guid.toString().raw());174 // Step 6: --------------------------------------------------175 // Use the IWbemServices pointer to make requests of WMI ----176 177 IEnumWbemClassObject* pEnumerator = NULL;178 hres = pSvc->ExecQuery(179 bstr_t("WQL"),180 bstr_t(aQueryString),181 WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,182 NULL,183 &pEnumerator);184 if(SUCCEEDED(hres))185 {186 // Step 7: -------------------------------------------------187 // Get the data from the query in step 6 -------------------188 189 IWbemClassObject *pclsObj;190 ULONG uReturn = 0;191 192 while (pEnumerator)193 {194 HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,195 &pclsObj, &uReturn);196 197 if(SUCCEEDED(hres))198 {199 if(uReturn)200 {201 pEnumerator->Release();202 *pAdapterConfig = pclsObj;203 hres = S_OK;204 return hres;205 }206 else207 {208 hres = S_FALSE;209 }210 }211 212 }213 pEnumerator->Release();214 }215 else216 {217 Log(("Query for operating system name failed. Error code = 0x%x\n", hres));218 }219 }220 221 return hres;222 }223 224 static HRESULT netIfWinAdapterConfigPath(IWbemClassObject *pObj, BSTR * pStr)225 {226 VARIANT index;227 228 // Get the value of the key property229 HRESULT hr = pObj->Get(L"Index", 0, &index, 0, 0);230 if(SUCCEEDED(hr))231 {232 WCHAR strIndex[8];233 swprintf(strIndex, L"%u", index.uintVal);234 *pStr = (bstr_t(L"Win32_NetworkAdapterConfiguration.Index='") + strIndex + "'").copy();235 }236 else237 {238 DWORD dwError = GetLastError();239 Assert(0);240 hr = HRESULT_FROM_WIN32( dwError );241 }242 return hr;243 }244 245 static HRESULT netIfExecMethod(IWbemServices * pSvc, IWbemClassObject *pClass, BSTR ObjPath,246 BSTR MethodName, LPWSTR *pArgNames, LPVARIANT *pArgs, UINT cArgs,247 IWbemClassObject** ppOutParams248 )249 {250 HRESULT hres = S_OK;251 // Step 6: --------------------------------------------------252 // Use the IWbemServices pointer to make requests of WMI ----253 254 ComPtr<IWbemClassObject> pInParamsDefinition;255 ComPtr<IWbemClassObject> pClassInstance;256 257 if(cArgs)258 {259 hres = pClass->GetMethod(MethodName, 0,260 pInParamsDefinition.asOutParam(), NULL);261 if(SUCCEEDED(hres))262 {263 hres = pInParamsDefinition->SpawnInstance(0, pClassInstance.asOutParam());264 265 if(SUCCEEDED(hres))266 {267 for(UINT i = 0; i < cArgs; i++)268 {269 // Store the value for the in parameters270 hres = pClassInstance->Put(pArgNames[i], 0,271 pArgs[i], 0);272 if(FAILED(hres))273 {274 break;275 }276 }277 }278 }279 }280 281 if(SUCCEEDED(hres))282 {283 IWbemClassObject* pOutParams = NULL;284 hres = pSvc->ExecMethod(ObjPath, MethodName, 0,285 NULL, pClassInstance, &pOutParams, NULL);286 if(SUCCEEDED(hres))287 {288 *ppOutParams = pOutParams;289 }290 }291 292 return hres;293 }294 295 static HRESULT netIfWinCreateIpArray(SAFEARRAY **ppArray, in_addr* aIp, UINT cIp)296 {297 HRESULT hr;298 SAFEARRAY * pIpArray = SafeArrayCreateVector(VT_BSTR, 0, cIp);299 if(pIpArray)300 {301 for(UINT i = 0; i < cIp; i++)302 {303 char* addr = inet_ntoa(aIp[i]);304 BSTR val = bstr_t(addr).copy();305 long aIndex[1];306 aIndex[0] = i;307 hr = SafeArrayPutElement(pIpArray, aIndex, val);308 if(FAILED(hr))309 {310 SysFreeString(val);311 SafeArrayDestroy(pIpArray);312 break;313 }314 }315 316 if(SUCCEEDED(hr))317 {318 *ppArray = pIpArray;319 }320 }321 else322 {323 DWORD dwError = GetLastError();324 Assert(0);325 hr = HRESULT_FROM_WIN32( dwError );326 }327 328 return hr;329 }330 331 static HRESULT netIfWinCreateIpArrayV4V6(SAFEARRAY **ppArray, BSTR Ip)332 {333 HRESULT hr;334 SAFEARRAY * pIpArray = SafeArrayCreateVector(VT_BSTR, 0, 1);335 if(pIpArray)336 {337 BSTR val = bstr_t(Ip, false).copy();338 long aIndex[1];339 aIndex[0] = 0;340 hr = SafeArrayPutElement(pIpArray, aIndex, val);341 if(FAILED(hr))342 {343 SysFreeString(val);344 SafeArrayDestroy(pIpArray);345 }346 347 if(SUCCEEDED(hr))348 {349 *ppArray = pIpArray;350 }351 }352 else353 {354 DWORD dwError = GetLastError();355 Assert(0);356 hr = HRESULT_FROM_WIN32( dwError );357 }358 359 return hr;360 }361 362 363 static HRESULT netIfWinCreateIpArrayVariantV4(VARIANT * pIpAddresses, in_addr* aIp, UINT cIp)364 {365 HRESULT hr;366 VariantInit(pIpAddresses);367 pIpAddresses->vt = VT_ARRAY | VT_BSTR;368 SAFEARRAY *pIpArray;369 hr = netIfWinCreateIpArray(&pIpArray, aIp, cIp);370 if(SUCCEEDED(hr))371 {372 pIpAddresses->parray = pIpArray;373 }374 return hr;375 }376 377 static HRESULT netIfWinCreateIpArrayVariantV4V6(VARIANT * pIpAddresses, BSTR Ip)378 {379 HRESULT hr;380 VariantInit(pIpAddresses);381 pIpAddresses->vt = VT_ARRAY | VT_BSTR;382 SAFEARRAY *pIpArray;383 hr = netIfWinCreateIpArrayV4V6(&pIpArray, Ip);384 if(SUCCEEDED(hr))385 {386 pIpAddresses->parray = pIpArray;387 }388 return hr;389 }390 391 static HRESULT netIfWinEnableStatic(IWbemServices * pSvc, BSTR ObjPath, VARIANT * pIp, VARIANT * pMask)392 {393 ComPtr<IWbemClassObject> pClass;394 BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration");395 HRESULT hr;396 if(ClassName)397 {398 hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL);399 if(SUCCEEDED(hr))400 {401 LPWSTR argNames[] = {L"IPAddress", L"SubnetMask"};402 LPVARIANT args[] = {pIp, pMask};403 ComPtr<IWbemClassObject> pOutParams;404 405 hr = netIfExecMethod(pSvc, pClass, ObjPath,406 bstr_t(L"EnableStatic"), argNames, args, 2, pOutParams.asOutParam());407 if(SUCCEEDED(hr))408 {409 VARIANT varReturnValue;410 hr = pOutParams->Get(bstr_t(L"ReturnValue"), 0,411 &varReturnValue, NULL, 0);412 Assert(SUCCEEDED(hr));413 if(SUCCEEDED(hr))414 {415 // Assert(varReturnValue.vt == VT_UINT);416 int winEr = varReturnValue.uintVal;417 switch(winEr)418 {419 case 0:420 hr = S_OK;421 break;422 default:423 hr = HRESULT_FROM_WIN32( winEr );424 break;425 }426 }427 }428 }429 SysFreeString(ClassName);430 }431 else432 {433 DWORD dwError = GetLastError();434 Assert(0);435 hr = HRESULT_FROM_WIN32( dwError );436 }437 438 return hr;439 }440 441 442 static HRESULT netIfWinEnableStaticV4(IWbemServices * pSvc, BSTR ObjPath, in_addr* aIp, in_addr * aMask, UINT cIp)443 {444 VARIANT ipAddresses;445 HRESULT hr = netIfWinCreateIpArrayVariantV4(&ipAddresses, aIp, cIp);446 if(SUCCEEDED(hr))447 {448 VARIANT ipMasks;449 hr = netIfWinCreateIpArrayVariantV4(&ipMasks, aMask, cIp);450 if(SUCCEEDED(hr))451 {452 netIfWinEnableStatic(pSvc, ObjPath, &ipAddresses, &ipMasks);453 VariantClear(&ipMasks);454 }455 VariantClear(&ipAddresses);456 }457 return hr;458 }459 460 static HRESULT netIfWinEnableStaticV4V6(IWbemServices * pSvc, BSTR ObjPath, BSTR Ip, BSTR Mask)461 {462 VARIANT ipAddresses;463 HRESULT hr = netIfWinCreateIpArrayVariantV4V6(&ipAddresses, Ip);464 if(SUCCEEDED(hr))465 {466 VARIANT ipMasks;467 hr = netIfWinCreateIpArrayVariantV4V6(&ipMasks, Mask);468 if(SUCCEEDED(hr))469 {470 netIfWinEnableStatic(pSvc, ObjPath, &ipAddresses, &ipMasks);471 VariantClear(&ipMasks);472 }473 VariantClear(&ipAddresses);474 }475 return hr;476 }477 478 /* win API allows to set gw metrics as well, we are not setting them */479 static HRESULT netIfWinSetGateways(IWbemServices * pSvc, BSTR ObjPath, VARIANT * pGw)480 {481 ComPtr<IWbemClassObject> pClass;482 BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration");483 HRESULT hr;484 if(ClassName)485 {486 hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL);487 if(SUCCEEDED(hr))488 {489 LPWSTR argNames[] = {L"DefaultIPGateway"};490 LPVARIANT args[] = {pGw};491 ComPtr<IWbemClassObject> pOutParams;492 493 hr = netIfExecMethod(pSvc, pClass, ObjPath,494 bstr_t(L"SetGateways"), argNames, args, 1, pOutParams.asOutParam());495 if(SUCCEEDED(hr))496 {497 VARIANT varReturnValue;498 hr = pOutParams->Get(bstr_t(L"ReturnValue"), 0,499 &varReturnValue, NULL, 0);500 Assert(SUCCEEDED(hr));501 if(SUCCEEDED(hr))502 {503 // Assert(varReturnValue.vt == VT_UINT);504 int winEr = varReturnValue.uintVal;505 switch(winEr)506 {507 case 0:508 hr = S_OK;509 break;510 default:511 hr = HRESULT_FROM_WIN32( winEr );512 break;513 }514 }515 } }516 SysFreeString(ClassName);517 }518 else519 {520 DWORD dwError = GetLastError();521 Assert(0);522 hr = HRESULT_FROM_WIN32( dwError );523 }524 525 return hr;526 }527 528 /* win API allows to set gw metrics as well, we are not setting them */529 static HRESULT netIfWinSetGatewaysV4(IWbemServices * pSvc, BSTR ObjPath, in_addr* aGw, UINT cGw)530 {531 VARIANT gwais;532 HRESULT hr = netIfWinCreateIpArrayVariantV4(&gwais, aGw, cGw);533 if(SUCCEEDED(hr))534 {535 netIfWinSetGateways(pSvc, ObjPath, &gwais);536 VariantClear(&gwais);537 }538 return hr;539 }540 541 /* win API allows to set gw metrics as well, we are not setting them */542 static HRESULT netIfWinSetGatewaysV4V6(IWbemServices * pSvc, BSTR ObjPath, BSTR Gw)543 {544 VARIANT vGw;545 HRESULT hr = netIfWinCreateIpArrayVariantV4V6(&vGw, Gw);546 if(SUCCEEDED(hr))547 {548 netIfWinSetGateways(pSvc, ObjPath, &vGw);549 VariantClear(&vGw);550 }551 return hr;552 }553 554 static HRESULT netIfWinEnableDHCP(IWbemServices * pSvc, BSTR ObjPath)555 {556 ComPtr<IWbemClassObject> pClass;557 BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration");558 HRESULT hr;559 if(ClassName)560 {561 hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL);562 if(SUCCEEDED(hr))563 {564 ComPtr<IWbemClassObject> pOutParams;565 566 hr = netIfExecMethod(pSvc, pClass, ObjPath,567 bstr_t(L"EnableDHCP"), NULL, NULL, 0, pOutParams.asOutParam());568 if(SUCCEEDED(hr))569 {570 VARIANT varReturnValue;571 hr = pOutParams->Get(bstr_t(L"ReturnValue"), 0,572 &varReturnValue, NULL, 0);573 Assert(SUCCEEDED(hr));574 if(SUCCEEDED(hr))575 {576 // Assert(varReturnValue.vt == VT_UINT);577 int winEr = varReturnValue.uintVal;578 switch(winEr)579 {580 case 0:581 hr = S_OK;582 break;583 default:584 hr = HRESULT_FROM_WIN32( winEr );585 break;586 }587 }588 }589 }590 SysFreeString(ClassName);591 }592 else593 {594 DWORD dwError = GetLastError();595 Assert(0);596 hr = HRESULT_FROM_WIN32( dwError );597 }598 599 return hr;600 }601 602 static HRESULT netIfWinDhcpRediscover(IWbemServices * pSvc, BSTR ObjPath)603 {604 ComPtr<IWbemClassObject> pClass;605 BSTR ClassName = SysAllocString(L"Win32_NetworkAdapterConfiguration");606 HRESULT hr;607 if(ClassName)608 {609 hr = pSvc->GetObject(ClassName, 0, NULL, pClass.asOutParam(), NULL);610 if(SUCCEEDED(hr))611 {612 ComPtr<IWbemClassObject> pOutParams;613 614 hr = netIfExecMethod(pSvc, pClass, ObjPath,615 bstr_t(L"ReleaseDHCPLease"), NULL, NULL, 0, pOutParams.asOutParam());616 if(SUCCEEDED(hr))617 {618 VARIANT varReturnValue;619 hr = pOutParams->Get(bstr_t(L"ReturnValue"), 0,620 &varReturnValue, NULL, 0);621 Assert(SUCCEEDED(hr));622 if(SUCCEEDED(hr))623 {624 // Assert(varReturnValue.vt == VT_UINT);625 int winEr = varReturnValue.uintVal;626 if(winEr == 0)627 {628 hr = netIfExecMethod(pSvc, pClass, ObjPath,629 bstr_t(L"RenewDHCPLease"), NULL, NULL, 0, pOutParams.asOutParam());630 if(SUCCEEDED(hr))631 {632 VARIANT varReturnValue;633 hr = pOutParams->Get(bstr_t(L"ReturnValue"), 0,634 &varReturnValue, NULL, 0);635 Assert(SUCCEEDED(hr));636 if(SUCCEEDED(hr))637 {638 // Assert(varReturnValue.vt == VT_UINT);639 int winEr = varReturnValue.uintVal;640 if(winEr == 0)641 {642 hr = S_OK;643 }644 else645 {646 hr = HRESULT_FROM_WIN32( winEr );647 }648 }649 }650 }651 else652 {653 hr = HRESULT_FROM_WIN32( winEr );654 }655 }656 }657 }658 SysFreeString(ClassName);659 }660 else661 {662 DWORD dwError = GetLastError();663 Assert(0);664 hr = HRESULT_FROM_WIN32( dwError );665 }666 667 return hr;668 }669 670 static int netIfWinIsDhcpEnabled(const Guid &guid, BOOL *pEnabled)671 {672 HRESULT hr;673 ComPtr <IWbemServices> pSvc;674 hr = netIfWinCreateIWbemServices(pSvc.asOutParam());675 if(SUCCEEDED(hr))676 {677 ComPtr <IWbemClassObject> pAdapterConfig;678 hr = netIfWinFindAdapterClassById(pSvc, guid, pAdapterConfig.asOutParam());679 if(SUCCEEDED(hr))680 {681 VARIANT vtEnabled;682 hr = pAdapterConfig->Get(L"DHCPEnabled", 0, &vtEnabled, 0, 0);683 if(SUCCEEDED(hr))684 {685 *pEnabled = vtEnabled.boolVal;686 }687 }688 }689 690 return SUCCEEDED(hr) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;691 }692 67 693 68 static int collectNetIfInfo(Bstr &strName, Guid &guid, PNETIFINFO pInfo) … … 787 162 } 788 163 789 BOOL bEnabled; 790 rc = netIfWinIsDhcpEnabled(guid, &bEnabled); 791 Assert(RT_SUCCESS(rc)); 792 if(RT_SUCCESS(rc)) 793 { 794 pInfo->bDhcpEnabled = bEnabled; 164 ADAPTER_SETTINGS Settings; 165 HRESULT hr = VBoxNetCfgWinGetAdapterSettings((const GUID *)guid.raw(), &Settings); 166 if(hr == S_OK) 167 { 168 pInfo->IPAddress.u = Settings.ip; 169 pInfo->IPNetMask.u = Settings.mask; 170 pInfo->bDhcpEnabled = Settings.bDhcp; 171 } 172 else 173 { 174 pInfo->bDhcpEnabled = false; 795 175 } 796 176 } … … 798 178 799 179 return VINF_SUCCESS; 800 }801 802 static int netIfEnableStaticIpConfigV6(const Guid & guid, IN_BSTR aIPV6Address, IN_BSTR aIPV6Mask, IN_BSTR aIPV6DefaultGateway)803 {804 HRESULT hr;805 ComPtr <IWbemServices> pSvc;806 hr = netIfWinCreateIWbemServices(pSvc.asOutParam());807 if(SUCCEEDED(hr))808 {809 ComPtr <IWbemClassObject> pAdapterConfig;810 hr = netIfWinFindAdapterClassById(pSvc, guid, pAdapterConfig.asOutParam());811 if(SUCCEEDED(hr))812 {813 BSTR ObjPath;814 hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);815 if(SUCCEEDED(hr))816 {817 hr = netIfWinEnableStaticV4V6(pSvc, ObjPath, aIPV6Address, aIPV6Mask);818 if(SUCCEEDED(hr))819 {820 if(aIPV6DefaultGateway)821 {822 hr = netIfWinSetGatewaysV4V6(pSvc, ObjPath, aIPV6DefaultGateway);823 }824 if(SUCCEEDED(hr))825 {826 // hr = netIfWinUpdateConfig(pIf);827 }828 }829 SysFreeString(ObjPath);830 }831 }832 }833 834 return SUCCEEDED(hr) ? VINF_SUCCESS : VERR_GENERAL_FAILURE;835 }836 837 static int netIfEnableStaticIpConfigV6(const Guid &guid, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)838 {839 #if 0840 RTNETADDRIPV6 Mask;841 int rc = prefixLength2IPv6Address(aIPV6MaskPrefixLength, &Mask);842 if(RT_SUCCESS(rc))843 {844 Bstr maskStr = composeIPv6Address(&Mask);845 rc = netIfEnableStaticIpConfigV6(guid, aIPV6Address, maskStr, NULL);846 }847 return rc;848 #else849 return VERR_NOT_IMPLEMENTED;850 #endif851 }852 853 static HRESULT netIfEnableDynamicIpConfig(const Guid &guid)854 {855 HRESULT hr;856 ComPtr <IWbemServices> pSvc;857 hr = netIfWinCreateIWbemServices(pSvc.asOutParam());858 if(SUCCEEDED(hr))859 {860 ComPtr <IWbemClassObject> pAdapterConfig;861 hr = netIfWinFindAdapterClassById(pSvc, guid, pAdapterConfig.asOutParam());862 if(SUCCEEDED(hr))863 {864 BOOL bIsHostOnly;865 hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly);866 if(SUCCEEDED(hr))867 {868 if(bIsHostOnly)869 {870 BSTR ObjPath;871 hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);872 if(SUCCEEDED(hr))873 {874 hr = netIfWinEnableDHCP(pSvc, ObjPath);875 if(SUCCEEDED(hr))876 {877 // hr = netIfWinUpdateConfig(pIf);878 }879 SysFreeString(ObjPath);880 }881 }882 else883 {884 hr = E_FAIL;885 }886 }887 }888 }889 890 891 return hr;892 }893 894 static HRESULT netIfDhcpRediscover(const Guid &guid)895 {896 HRESULT hr;897 ComPtr <IWbemServices> pSvc;898 hr = netIfWinCreateIWbemServices(pSvc.asOutParam());899 if(SUCCEEDED(hr))900 {901 ComPtr <IWbemClassObject> pAdapterConfig;902 hr = netIfWinFindAdapterClassById(pSvc, guid, pAdapterConfig.asOutParam());903 if(SUCCEEDED(hr))904 {905 BOOL bIsHostOnly;906 hr = netIfWinIsHostOnly(pAdapterConfig, &bIsHostOnly);907 if(SUCCEEDED(hr))908 {909 if(bIsHostOnly)910 {911 BSTR ObjPath;912 hr = netIfWinAdapterConfigPath(pAdapterConfig, &ObjPath);913 if(SUCCEEDED(hr))914 {915 hr = netIfWinDhcpRediscover(pSvc, ObjPath);916 if(SUCCEEDED(hr))917 {918 // hr = netIfWinUpdateConfig(pIf);919 }920 SysFreeString(ObjPath);921 }922 }923 else924 {925 hr = E_FAIL;926 }927 }928 }929 }930 931 932 return hr;933 180 } 934 181
Note:
See TracChangeset
for help on using the changeset viewer.