掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
ネットワークアダプタを無効に (ID:52762)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
[なーめ 2003/12/08(月) 19:56:45] を VisualC++ 6.0 のダイアログアプリの OnOK() にて 書いてみました。 #include <Wbemcli.h> #include <WbemProv.h> void ReportError( HRESULT hr ) { char * msg; switch( hr ) { case WBEM_E_ACCESS_DENIED: msg = "The current or specified user name and password were not valid or authorized to make the connection."; break; case WBEM_E_FAILED: msg = "This indicates other unspecified errors."; break; case WBEM_E_INVALID_NAMESPACE: //msg = "The specified namespace did not exist on the server."; msg = "サーバにそのような名前空間はありません"; break; case WBEM_E_INVALID_PARAMETER: msg = "An invalid parameter was specified."; break; case WBEM_E_INVALID_QUERY: msg = "The query was not syntactically valid."; break; case WBEM_E_INVALID_QUERY_TYPE: msg = "The requested query language is not supported."; break; case WBEM_E_OUT_OF_MEMORY: msg = "There was not enough memory to complete the operation."; break; case WBEM_E_SHUTTING_DOWN: msg = "Windows Management service was probably stopped and restarted. A new call to ConnectServer is needed."; break; case WBEM_E_TRANSPORT_FAILURE: msg = "This indicates the failure of the remote procedure call (RPC) link between the current process and Windows Management."; break; case WBEM_E_NOT_FOUND: msg = "The query specifies a class that does not exist."; break; case WBEM_E_LOCAL_CREDENTIALS: msg = "WMI is passing the user credential on local connection.\n"; break; case WBEM_E_UNEXPECTED: msg = "An object in the enumeration has been deleted, destroying the validity of the enumeration."; break; case WBEM_S_FALSE: msg = "WBEM_S_FALSE(The number of objects returned was less than the number requested. WBEM_S_FALSE is also returned when this method is called with a value of 0 for the uCount parameter.)"; break; case WBEM_S_TIMEDOUT: msg = "A time-out occurred before you obtained all the objects."; break; default: case WBEM_S_NO_ERROR: //msg = "The call succeeded."; msg = "呼び出しは正常に処理されました"; break; } TRACE("%s\n", msg ); } #if 0 case : msg = ""; break; #endif #ifndef WBEM_MAX_OBJECT_NESTING #define WBEM_MAX_OBJECT_NESTING 256 #endif void CW02Dlg::OnOK() { DWORD dwCTX = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER; IWbemServices * pWbemServices = NULL; IWbemLocator * pWbemLocator = NULL; IWbemContext * pWbemContext = NULL; // IWbemClassObject* m_pIWbemObject[WBEM_MAX_OBJECT_NESTING]; IWbemClassObject* pIWbemObject; CStringArray acsNames; int nCntNames = 0; // NameSpace に "winmgmts:" はつけない。 // BSTR bstrNamespace = L"winmgmts:{impersonationLevel=impersonate}"; // BSTR bstrNamespace = SysAllocString(L"{impersonationLevel=impersonate}"); BSTR bstrNamespace = SysAllocString(L"\\\\.\\root\\cimv2"); BSTR bstrUser = SysAllocString(L"tutumi"); BSTR bstrPasswd = SysAllocString(L"Logical"); BSTR bstrLocale = NULL; long lSecurityFlags = 0; // WBEM_FLAG_CONNECT_USE_MAX_WAIT; BSTR bstrAuthority = NULL; HRESULT hr; if(( hr = CoCreateInstance( CLSID_WbemAdministrativeLocator,NULL,dwCTX,IID_IUnknown ,(void **) &pWbemLocator )) == S_OK ) { if(( hr = pWbemLocator->ConnectServer( bstrNamespace, bstrUser, bstrPasswd, bstrLocale, lSecurityFlags, bstrAuthority, pWbemContext, &pWbemServices )) == S_OK ) { CComBSTR ccbsQueryLanguage = L"WQL"; // CComBSTR ccbsQuery = L"Select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE"; CComBSTR ccbsQuery = L"Select Name from Win32_NetworkAdapter"; long lFlags = WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY; IWbemContext* pCtx = NULL; IEnumWbemClassObject * pEnum; if(( pWbemServices->ExecQuery( ccbsQueryLanguage, ccbsQuery, lFlags, pCtx, &pEnum )) == S_OK ) { unsigned long bGotton; unsigned long bFound = 0; while( pEnum->Next( WBEM_INFINITE, 1, &pIWbemObject, &bGotton ) == WBEM_S_NO_ERROR ) { long cimtype; CComVariant v; CComBSTR ccbsName; _bstr_t bs; pIWbemObject->BeginEnumeration( 0 ); while( pIWbemObject->Next( 0, &ccbsName, &v, &cimtype, NULL ) == WBEM_S_NO_ERROR ) { char s[1024]; strcpy( s, (char *)( bs = ccbsName )); if( s[0] != '_') { if(! strcmp( s, "Name" )) { if(( pIWbemObject->Get(L"Name",0,&v,0,0)) == WBEM_S_NO_ERROR ) { _bstr_t bstName = v; //TRACE("Name: %s\n", (char *)bstName ); acsNames.SetAtGrow( nCntNames++, (char *)bstName ); } } else { TRACE("XXX[%08X]: %s\n", cimtype, s ); } } } pIWbemObject->EndEnumeration(); pIWbemObject->Release(); bFound ++; } pEnum->Release(); if( bFound == 0 ) { TRACE("ENUM: NoData Found.\n"); } } else { TRACE("ExecQuery - Failed.\n"); TRACE("HR=0x%08X.\n", hr ); ReportError( hr ); } pWbemServices->Release(); } else { TRACE("ConnectServer - Failed.\n"); TRACE("HR=0x%08X.\n", hr ); ReportError( hr ); } pWbemLocator->Release(); // } else { MessageBox("IWbemLocator: Failed.", "ERROR", MB_ICONSTOP ); TRACE("HR=0x%08X.\n", hr ); } SysFreeString( bstrPasswd ); SysFreeString( bstrUser ); SysFreeString( bstrNamespace ); int c; for( c = 0; c < nCntNames; c ++ ) { TRACE("NAME: %s\n", acsNames[c] ); } //CDialog::OnOK(); }
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.