JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » .Net Framework  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Re:[問題]請教一個WMI使用的問題 [Re:ppoppo]
ray_linn

什么都不懂的小白

版主

發文: 540
積分: 10
於 2004-09-23 11:12 user profilesend a private message to usersend email to ray_linnreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
CoInitialize(NULL);
 
if(CoInitializeSecurity( NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
0
) != S_OK)
    return;
 
IWbemLocator * pIWbemLocator = NULL;
IWbemServices * pWbemServices = NULL;
IEnumWbemClassObject * pEnumObject = NULL;
BSTR bstrNamespace = (L"root\\cimv2");
HRESULT hRes = CoCreateInstance (
  CLSID_WbemAdministrativeLocator,
  NULL ,
  CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER , 
  IID_IUnknown ,
  ( void ** ) & pIWbemLocator
  ) ;
if (SUCCEEDED(hRes))
{
  hRes = pIWbemLocator->ConnectServer(
  bstrNamespace, // Namespace
  NULL, // Userid
  NULL, // PW
  NULL, // Locale
  0, // flags
  NULL, // Authority
  NULL, // Context
  &pWbemServices
  );
}
BSTR strQuery = (L"Select * from win32_Processor");
BSTR strQL = (L"WQL");
hRes = pWbemServices->ExecQuery(strQL, strQuery,
  WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);
 
ULONG uCount = 1, uReturned;
IWbemClassObject * pClassObject = NULL;
hRes = pEnumObject->Reset();
hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject, &uReturned);
VARIANT v;
BSTR strClassProp = SysAllocString(L"LoadPercentage");
hRes = pClassObject->Get(strClassProp, 0, &v, 0, 0);
SysFreeString(strClassProp);
 
_bstr_t bstrPath = &v; //Just to convert BSTR to ANSI
char* strPath=(char*)bstrPath;
if (SUCCEEDED(hRes))
MessageBox(strPath);
else
MessageBox(”Error in getting object”);
VariantClear( &v );
pIWbemLocator->Release();
pWbemServices->Release();
pEnumObject->Release();
pClassObject->Release();
CoUninitialize();


reply to postreply to post
飞翔的候鸟
話題樹型展開
人氣 標題 作者 字數 發文時間
3926 [問題]請教一個WMI使用的問題 ppoppo 723 2004-09-17 10:17
3355 Re:[問題]請教一個WMI使用的問題 ray_linn 1606 2004-09-23 11:12
3394 Re:[問題]請教一個WMI使用的問題 ppoppo 56 2004-09-30 11:46
3289 Re:[問題]請教一個WMI使用的問題 aegir 149 2005-01-10 16:29
» JWorld@TW »  .Net Framework

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8