Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2967 lines
91 KiB

  1. /*****************************************************************************
  2. Copyright information : Copyright (c) 1998-1999 Microsoft Corporation
  3. File Name : CmdAlias.cpp
  4. Project Name : WMI Command Line
  5. Author Name : Ch. Sriramachandramurthy
  6. Date of Creation (dd/mm/yy) : 27th-September-2000
  7. Version Number : 1.0
  8. Brief Description : The CmdAlias class encapsulates the
  9. functionality for retrieving alias information.
  10. Revision History :
  11. Last Modified By : C V Nandi
  12. Last Modified Date : 16th-March-2001
  13. *****************************************************************************/
  14. #include "Precomp.h"
  15. #include "GlobalSwitches.h"
  16. #include "CommandSwitches.h"
  17. #include "HelpInfo.h"
  18. #include "ErrorLog.h"
  19. #include "ParsedInfo.h"
  20. #include "CmdAlias.h"
  21. #include "CmdTokenizer.h"
  22. #include "ErrorInfo.h"
  23. #include "WMICliXMLLog.h"
  24. #include "ParserEngine.h"
  25. #include "ExecEngine.h"
  26. #include "FormatEngine.h"
  27. #include "WmiCmdLn.h"
  28. /*----------------------------------------------------------------------------
  29. Name :CCmdAlias
  30. Synopsis :This function initializes the member variables when an
  31. object of the class type is instantiated.
  32. Type :Constructor
  33. Input parameter :None
  34. Output parameters :None
  35. Return Type :None
  36. Global Variables :None
  37. Calling Syntax :None
  38. Notes :None
  39. ----------------------------------------------------------------------------*/
  40. CCmdAlias::CCmdAlias()
  41. {
  42. m_pIAliasNS = NULL;
  43. m_pILocalizedNS = NULL;
  44. m_bTrace = FALSE;
  45. m_eloErrLogOpt = NO_LOGGING;
  46. }
  47. /*----------------------------------------------------------------------------
  48. Name :~CCmdAlias
  49. Synopsis :This function uninitializes the member variables when an
  50. object of the class type goes out of scope.
  51. Type :Destructor
  52. Input parameter :None
  53. Output parameters :None
  54. Return Type :None
  55. Global Variables :None
  56. Calling Syntax :None
  57. Notes :None
  58. ----------------------------------------------------------------------------*/
  59. CCmdAlias::~CCmdAlias()
  60. {
  61. SAFEIRELEASE(m_pIAliasNS);
  62. SAFEIRELEASE(m_pILocalizedNS);
  63. }
  64. /*----------------------------------------------------------------------------
  65. Name :Uninitialize
  66. Synopsis :This function uninitializes the member variables when
  67. the execution of a command string issued on the command
  68. line is completed.
  69. Type :Member Function
  70. Input Parameter(s):
  71. bFinal - boolean value which when set indicates that the program
  72. Output parameters :None
  73. Return Type :None
  74. Global Variables :None
  75. Calling Syntax :Uninitialize(bFinal)
  76. Notes :None
  77. ----------------------------------------------------------------------------*/
  78. void CCmdAlias::Uninitialize(BOOL bFinal)
  79. {
  80. m_bTrace = FALSE;
  81. // If end of program
  82. if (bFinal)
  83. {
  84. SAFEIRELEASE(m_pILocalizedNS);
  85. SAFEIRELEASE(m_pIAliasNS);
  86. }
  87. }
  88. /*----------------------------------------------------------------------------
  89. Name :ConnectToAlias
  90. Synopsis :This function connects to WMI namespace on the specified
  91. machine using the information available CParsedInfo
  92. class object.
  93. Type :Member Function
  94. Input parameter(s):
  95. rParsedInfo - reference to CParsedInfo class object.
  96. pIWbemLocator - IWbemLocator object for connecting to WMI .
  97. Output parameter(s):
  98. rParsedInfo - reference to CParsedInfo class object.
  99. Return Type :HRESULT
  100. Global Variables :None
  101. Calling Syntax :ConnectToAlias(rParsedInfo,pIWbemLocator)
  102. Notes :None
  103. ----------------------------------------------------------------------------*/
  104. HRESULT CCmdAlias::ConnectToAlias(CParsedInfo& rParsedInfo,
  105. IWbemLocator* pIWbemLocator)
  106. {
  107. // Get current thread for logging the success or failure of the command.
  108. DWORD dwThreadId = GetCurrentThreadId();
  109. HRESULT hr = S_OK;
  110. // Set the trace flag
  111. m_bTrace = rParsedInfo.GetGlblSwitchesObject().GetTraceStatus();
  112. m_eloErrLogOpt = rParsedInfo.GetErrorLogObject().GetErrLogOption();
  113. try
  114. {
  115. // If the /ROLE has been changed since last invocation
  116. if (rParsedInfo.GetGlblSwitchesObject().GetRoleFlag() == TRUE)
  117. {
  118. SAFEIRELEASE(m_pIAliasNS);
  119. CHString chsMsg;
  120. // Connect to the specified namespace of Windows Management on the
  121. // local computer using the locator object.
  122. hr = Connect(pIWbemLocator, &m_pIAliasNS,
  123. _bstr_t(rParsedInfo.GetGlblSwitchesObject().GetRole()),
  124. NULL, NULL, _bstr_t(rParsedInfo.GetGlblSwitchesObject().
  125. GetLocale()), rParsedInfo);
  126. // If /TRACE is ON
  127. if (m_bTrace || m_eloErrLogOpt)
  128. {
  129. chsMsg.Format(
  130. L"IWbemLocator::ConnectServer(L\"%s\", NULL, NULL, "
  131. L"L\"%s\", 0L, NULL, NULL, -)",
  132. rParsedInfo.GetGlblSwitchesObject().GetRole(),
  133. rParsedInfo.GetGlblSwitchesObject().GetLocale());
  134. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  135. dwThreadId, rParsedInfo, m_bTrace);
  136. }
  137. ONFAILTHROWERROR(hr);
  138. // Set the interface level security
  139. hr =
  140. SetSecurity(m_pIAliasNS, NULL, NULL, NULL, NULL,
  141. rParsedInfo.GetGlblSwitchesObject().GetAuthenticationLevel(),
  142. rParsedInfo.GetGlblSwitchesObject().GetImpersonationLevel());
  143. // If /TRACE is ON
  144. if (m_bTrace || m_eloErrLogOpt)
  145. {
  146. chsMsg.Format(L"CoSetProxyBlanket(-, RPC_C_AUTHN_WINNT, "
  147. L"RPC_C_AUTHZ_NONE, NULL, %d, %d, -, EOAC_NONE)",
  148. rParsedInfo.GetGlblSwitchesObject().GetAuthenticationLevel(),
  149. rParsedInfo.GetGlblSwitchesObject().GetImpersonationLevel());
  150. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  151. dwThreadId, rParsedInfo, m_bTrace);
  152. }
  153. ONFAILTHROWERROR(hr);
  154. rParsedInfo.GetGlblSwitchesObject().SetRoleFlag(FALSE);
  155. }
  156. // Connect to the localized Namespace
  157. hr = ConnectToLocalizedNS(rParsedInfo, pIWbemLocator);
  158. ONFAILTHROWERROR(hr);
  159. }
  160. catch(_com_error& e)
  161. {
  162. // Set the COM error
  163. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  164. hr = e.Error();
  165. }
  166. catch(CHeap_Exception)
  167. {
  168. hr = WBEM_E_OUT_OF_MEMORY;
  169. _com_issue_error(hr);
  170. }
  171. return hr;
  172. }
  173. /*----------------------------------------------------------------------------
  174. Name :ObtainAliasInfo
  175. Synopsis :Obtains the following info of the alias specified.
  176. 1. alias PWhere expression
  177. 2. alias target string
  178. 3. alias description
  179. from the alias definition and updates the information in
  180. the CParsedInfo object passed as reference.
  181. Type :Member Function
  182. Input parameter(s):
  183. rParsedInfo - The parsed info from command line input.
  184. Output parameter(s):
  185. rParsedInfo - The parsed info from command line input.
  186. Return Type :RETCODE
  187. Global Variables :None
  188. Calling Syntax :ObtainAliasInfo(rParsedInfo)
  189. Notes :None
  190. ----------------------------------------------------------------------------*/
  191. RETCODE CCmdAlias::ObtainAliasInfo(CParsedInfo& rParsedInfo)
  192. {
  193. // Variables being used in this function.
  194. IWbemClassObject *pIWbemObj = NULL;
  195. IUnknown *pIUnknown = NULL;
  196. IWbemClassObject *pIEmbedObj = NULL;
  197. HRESULT hr = S_OK;
  198. RETCODE retCode = PARSER_CONTINUE;
  199. DWORD dwThreadId = GetCurrentThreadId();
  200. // Variants to save the properties and also for the embedded objects.
  201. VARIANT vtProp, vtEmbedProp;
  202. VariantInit(&vtProp);
  203. VariantInit(&vtEmbedProp);
  204. try
  205. {
  206. _bstr_t bstrResult;
  207. CHString chsMsg;
  208. // Object path of the required alias.
  209. _bstr_t bstrPath = _bstr_t("MSFT_CliAlias.FriendlyName='") +
  210. _bstr_t(rParsedInfo.GetCmdSwitchesObject().
  211. GetAliasName()) + _bstr_t(L"'");
  212. //Retrieving the object from the namespace in m_pIAliasNS
  213. hr = m_pIAliasNS->GetObject(bstrPath, 0, NULL, &pIWbemObj, NULL);
  214. if (m_bTrace || m_eloErrLogOpt)
  215. {
  216. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  217. (WCHAR*) bstrPath);
  218. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  219. dwThreadId, rParsedInfo, m_bTrace);
  220. }
  221. // To set errata code that indicates a more user friendly error
  222. // message to the user.
  223. if ( FAILED ( hr ) )
  224. {
  225. // Don't set com error in catch block.
  226. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  227. IDS_E_ALIAS_NOT_FOUND);
  228. }
  229. ONFAILTHROWERROR(hr);
  230. //1. Retrieve the value of 'Target' property object
  231. hr = pIWbemObj->Get(_bstr_t(L"Target"), 0, &vtProp, 0, 0 );
  232. if (m_bTrace || m_eloErrLogOpt)
  233. {
  234. chsMsg.Format(L"IWbemClassObject::Get(L\"Target\", 0, -, 0, 0)");
  235. GetBstrTFromVariant(vtProp, bstrResult);
  236. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  237. (LPCWSTR)chsMsg, dwThreadId, rParsedInfo,
  238. m_bTrace, 0, bstrResult);
  239. }
  240. ONFAILTHROWERROR(hr);
  241. if (vtProp.vt != VT_NULL && vtProp.vt != VT_EMPTY)
  242. {
  243. if(!rParsedInfo.GetCmdSwitchesObject().SetAliasTarget(
  244. (_TCHAR*)vtProp.bstrVal))
  245. {
  246. rParsedInfo.GetCmdSwitchesObject().
  247. SetErrataCode(OUT_OF_MEMORY);
  248. retCode = PARSER_OUTOFMEMORY;
  249. }
  250. }
  251. if(retCode != PARSER_OUTOFMEMORY)
  252. {
  253. VARIANTCLEAR(vtProp);
  254. //2. Retrieve the value of 'PWhere' property object
  255. VariantInit(&vtProp);
  256. hr = pIWbemObj->Get(_bstr_t(L"PWhere"), 0, &vtProp, 0, 0);
  257. if (m_bTrace || m_eloErrLogOpt)
  258. {
  259. chsMsg.Format(L"IWbemClassObject::Get(L\"PWhere\", 0, -,"
  260. L"0, 0)");
  261. GetBstrTFromVariant(vtProp, bstrResult);
  262. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  263. dwThreadId, rParsedInfo, m_bTrace,
  264. 0, bstrResult);
  265. }
  266. ONFAILTHROWERROR(hr);
  267. if (vtProp.vt != VT_NULL && vtProp.vt != VT_EMPTY)
  268. {
  269. if(!rParsedInfo.GetCmdSwitchesObject().SetPWhereExpr(
  270. (_TCHAR*)vtProp.bstrVal))
  271. {
  272. rParsedInfo.GetCmdSwitchesObject().
  273. SetErrataCode(OUT_OF_MEMORY);
  274. retCode = PARSER_OUTOFMEMORY;
  275. }
  276. }
  277. if(retCode != PARSER_OUTOFMEMORY)
  278. {
  279. VARIANTCLEAR(vtProp);
  280. // Retrieve the "Connection" property value
  281. VariantInit(&vtProp);
  282. hr = pIWbemObj->Get(_bstr_t(L"Connection"), 0, &vtProp, 0, 0);
  283. if (m_bTrace || m_eloErrLogOpt)
  284. {
  285. chsMsg.Format(L"IWbemClassObject::Get(L\"Connection\","
  286. L"0, -, 0, 0)");
  287. GetBstrTFromVariant(vtProp, bstrResult);
  288. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  289. dwThreadId, rParsedInfo, m_bTrace,
  290. 0, bstrResult);
  291. }
  292. ONFAILTHROWERROR(hr);
  293. if (vtProp.vt != VT_NULL && vtProp.vt != VT_EMPTY)
  294. {
  295. pIUnknown = vtProp.punkVal;
  296. hr = pIUnknown->QueryInterface(IID_IWbemClassObject,
  297. (void**)&pIEmbedObj);
  298. if (m_bTrace || m_eloErrLogOpt)
  299. {
  300. chsMsg.Format(L"QueryInterface("
  301. L"IID_IWbemClassObject, -)");
  302. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  303. (LPCWSTR)chsMsg, dwThreadId,
  304. rParsedInfo, m_bTrace);
  305. }
  306. ONFAILTHROWERROR(hr);
  307. retCode =
  308. ObtainAliasConnectionInfo(rParsedInfo, pIEmbedObj);
  309. //Releasing the embedded object.
  310. SAFEIRELEASE(pIEmbedObj);
  311. VARIANTCLEAR(vtProp);
  312. }
  313. }
  314. }
  315. // Obtain the alias description
  316. if (retCode != PARSER_OUTOFMEMORY)
  317. {
  318. _bstr_t bstrDesc;
  319. hr = GetDescOfObject(pIWbemObj, bstrDesc, rParsedInfo, TRUE);
  320. ONFAILTHROWERROR(hr);
  321. if(!rParsedInfo.GetCmdSwitchesObject().
  322. SetAliasDesc((_TCHAR*)bstrDesc))
  323. {
  324. rParsedInfo.GetCmdSwitchesObject().
  325. SetErrataCode(OUT_OF_MEMORY);
  326. retCode = PARSER_OUTOFMEMORY;
  327. }
  328. }
  329. SAFEIRELEASE(pIWbemObj);
  330. }
  331. catch(_com_error& e)
  332. {
  333. SAFEIRELEASE(pIWbemObj);
  334. SAFEIRELEASE(pIEmbedObj);
  335. VARIANTCLEAR(vtProp);
  336. VARIANTCLEAR(vtEmbedProp);
  337. // No errata code then set com error.
  338. if ( rParsedInfo.GetCmdSwitchesObject().GetErrataCode() == 0 )
  339. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  340. retCode = PARSER_ERRMSG;
  341. }
  342. catch(CHeap_Exception)
  343. {
  344. SAFEIRELEASE(pIWbemObj);
  345. SAFEIRELEASE(pIEmbedObj);
  346. VARIANTCLEAR(vtProp);
  347. VARIANTCLEAR(vtEmbedProp);
  348. retCode = PARSER_ERRMSG;
  349. hr = WBEM_E_OUT_OF_MEMORY;
  350. _com_issue_error(hr);
  351. }
  352. return retCode;
  353. }
  354. /*----------------------------------------------------------------------------
  355. Name :ObtainAliasConnectionInfo
  356. Synopsis : Obtain the alias connection information like
  357. 1. namespace 2. user 3. password
  358. 4. locale 5. server 6. authority
  359. Type :Member Function
  360. Input parameter(s):
  361. rParsedInfo - The parsed info from command line input.
  362. pIEmbedObj - Pointer to the IWbem class object
  363. Output parameter(s):
  364. rParsedInfo - The parsed info from command line input.
  365. Return Type :RETCODE
  366. Global Variables :None
  367. Calling Syntax :ObtainAliasConnectionInfo(rParsedInfo)
  368. Notes :None
  369. ----------------------------------------------------------------------------*/
  370. RETCODE CCmdAlias::ObtainAliasConnectionInfo(CParsedInfo& rParsedInfo,
  371. IWbemClassObject* pIEmbedObj)
  372. {
  373. RETCODE retCode = PARSER_CONTINUE;
  374. HRESULT hr = S_OK;
  375. UINT uConnFlag = 0;
  376. DWORD dwThreadId = GetCurrentThreadId();
  377. VARIANT vtEmbedProp;
  378. VariantInit(&vtEmbedProp);
  379. uConnFlag = rParsedInfo.GetGlblSwitchesObject().GetConnInfoFlag();
  380. try
  381. {
  382. CHString chsMsg;
  383. _bstr_t bstrResult;
  384. if (!(uConnFlag & NAMESPACE))
  385. {
  386. // retrieve the value of 'Namespace' property
  387. hr = pIEmbedObj->Get(_bstr_t(L"Namespace"), 0, &vtEmbedProp, 0,0);
  388. if (m_bTrace || m_eloErrLogOpt)
  389. {
  390. chsMsg.Format(L"IWbemClassObject::Get(L\"Namespace\", 0, -,"
  391. L"0, 0)");
  392. GetBstrTFromVariant(vtEmbedProp, bstrResult);
  393. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  394. dwThreadId, rParsedInfo, m_bTrace,
  395. 0, bstrResult);
  396. }
  397. ONFAILTHROWERROR(hr);
  398. if (vtEmbedProp.vt != VT_NULL && vtEmbedProp.vt != VT_EMPTY)
  399. {
  400. if(!rParsedInfo.GetCmdSwitchesObject().SetAliasNamespace(
  401. (_TCHAR*)vtEmbedProp.bstrVal))
  402. {
  403. rParsedInfo.GetCmdSwitchesObject().
  404. SetErrataCode(OUT_OF_MEMORY);
  405. retCode = PARSER_OUTOFMEMORY;
  406. }
  407. VARIANTCLEAR(vtEmbedProp);
  408. }
  409. }
  410. if(retCode != PARSER_OUTOFMEMORY)
  411. {
  412. if (!(uConnFlag & LOCALE))
  413. {
  414. // retrieve the value of 'Locale' property
  415. hr = pIEmbedObj->Get(_bstr_t(L"Locale"), 0, &vtEmbedProp,0,0);
  416. if (m_bTrace || m_eloErrLogOpt)
  417. {
  418. chsMsg.Format(L"IWbemClassObject::Get(L\"Locale\", 0,"
  419. L"-, 0, 0)");
  420. GetBstrTFromVariant(vtEmbedProp, bstrResult);
  421. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  422. dwThreadId, rParsedInfo, m_bTrace,
  423. 0, bstrResult);
  424. }
  425. ONFAILTHROWERROR(hr);
  426. if (vtEmbedProp.vt != VT_NULL && vtEmbedProp.vt != VT_EMPTY)
  427. {
  428. if(!rParsedInfo.GetCmdSwitchesObject().SetAliasLocale(
  429. (_TCHAR*)vtEmbedProp.bstrVal))
  430. {
  431. rParsedInfo.GetCmdSwitchesObject().
  432. SetErrataCode(OUT_OF_MEMORY);
  433. retCode = PARSER_OUTOFMEMORY;
  434. }
  435. VARIANTCLEAR(vtEmbedProp);
  436. }
  437. }
  438. if(retCode != PARSER_OUTOFMEMORY)
  439. {
  440. if (!(uConnFlag & USER))
  441. {
  442. // retrieve the value of 'User' property
  443. hr =
  444. pIEmbedObj->Get(_bstr_t(L"User"), 0, &vtEmbedProp, 0,0);
  445. if (m_bTrace || m_eloErrLogOpt)
  446. {
  447. chsMsg.Format(L"IWbemClassObject::Get(L\"User\", 0,"
  448. L"-, 0, 0)");
  449. GetBstrTFromVariant(vtEmbedProp, bstrResult);
  450. WMITRACEORERRORLOG( hr, __LINE__, __FILE__,
  451. (LPCWSTR)chsMsg, dwThreadId,
  452. rParsedInfo, m_bTrace,
  453. 0, bstrResult );
  454. }
  455. ONFAILTHROWERROR(hr);
  456. if (vtEmbedProp.vt != VT_NULL &&
  457. vtEmbedProp.vt != VT_EMPTY)
  458. {
  459. if(!rParsedInfo.GetCmdSwitchesObject().SetAliasUser(
  460. (_TCHAR*)vtEmbedProp.bstrVal))
  461. {
  462. rParsedInfo.GetCmdSwitchesObject().
  463. SetErrataCode(OUT_OF_MEMORY);
  464. retCode = PARSER_OUTOFMEMORY;
  465. }
  466. VARIANTCLEAR(vtEmbedProp);
  467. }
  468. }
  469. if(retCode != PARSER_OUTOFMEMORY)
  470. {
  471. if (!(uConnFlag & PASSWORD))
  472. {
  473. // retrieve the value of 'Password' property
  474. hr = pIEmbedObj->Get(_bstr_t(L"Password"),
  475. 0, &vtEmbedProp, 0,0);
  476. if (m_bTrace || m_eloErrLogOpt)
  477. {
  478. chsMsg.Format(L"IWbemClassObject::Get"
  479. L"(L\"Password\", 0, -, 0, 0)");
  480. GetBstrTFromVariant(vtEmbedProp, bstrResult);
  481. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  482. (LPCWSTR)chsMsg, dwThreadId,
  483. rParsedInfo, m_bTrace,
  484. 0, bstrResult);
  485. }
  486. ONFAILTHROWERROR(hr);
  487. if (vtEmbedProp.vt != VT_NULL &&
  488. vtEmbedProp.vt != VT_EMPTY)
  489. {
  490. if(!rParsedInfo.GetCmdSwitchesObject().
  491. SetAliasPassword((_TCHAR*)vtEmbedProp.bstrVal))
  492. {
  493. rParsedInfo.GetCmdSwitchesObject().
  494. SetErrataCode(OUT_OF_MEMORY);
  495. retCode = PARSER_OUTOFMEMORY;
  496. }
  497. VARIANTCLEAR(vtEmbedProp);
  498. }
  499. }
  500. if(retCode != PARSER_OUTOFMEMORY)
  501. {
  502. if (!(uConnFlag & NODE))
  503. {
  504. // retrieve the value of 'Server' property
  505. hr = pIEmbedObj->Get(_bstr_t(L"Server"),
  506. 0, &vtEmbedProp, 0,0);
  507. if (m_bTrace || m_eloErrLogOpt)
  508. {
  509. chsMsg.Format(L"IWbemClassObject::Get"
  510. L"(L\"Server\", 0, -, 0, 0)");
  511. GetBstrTFromVariant(vtEmbedProp, bstrResult);
  512. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  513. (LPCWSTR)chsMsg,dwThreadId,
  514. rParsedInfo, m_bTrace,
  515. 0, bstrResult);
  516. }
  517. ONFAILTHROWERROR(hr);
  518. if (vtEmbedProp.vt != VT_NULL &&
  519. vtEmbedProp.vt != VT_EMPTY)
  520. {
  521. if(!rParsedInfo.GetCmdSwitchesObject().
  522. SetAliasNode((_TCHAR*)vtEmbedProp.bstrVal))
  523. {
  524. rParsedInfo.GetCmdSwitchesObject().
  525. SetErrataCode(OUT_OF_MEMORY);
  526. retCode = PARSER_OUTOFMEMORY;
  527. }
  528. VARIANTCLEAR(vtEmbedProp);
  529. }
  530. }
  531. if (retCode != PARSER_OUTOFMEMORY)
  532. {
  533. // retrieve the value of 'Authority' property
  534. hr = pIEmbedObj->Get(_bstr_t(L"Authority"),
  535. 0, &vtEmbedProp, 0,0);
  536. if (m_bTrace || m_eloErrLogOpt)
  537. {
  538. chsMsg.Format(L"IWbemClassObject::Get"
  539. L"(L\"Authority\", 0, -, 0, 0)");
  540. GetBstrTFromVariant(vtEmbedProp, bstrResult);
  541. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  542. (LPCWSTR)chsMsg,dwThreadId,
  543. rParsedInfo, m_bTrace,
  544. 0, bstrResult);
  545. }
  546. ONFAILTHROWERROR(hr);
  547. if (vtEmbedProp.vt != VT_NULL &&
  548. vtEmbedProp.vt != VT_EMPTY)
  549. {
  550. if(!rParsedInfo.GetGlblSwitchesObject().
  551. SetAuthority((_TCHAR*)vtEmbedProp.bstrVal))
  552. {
  553. rParsedInfo.GetCmdSwitchesObject().
  554. SetErrataCode(OUT_OF_MEMORY);
  555. retCode = PARSER_OUTOFMEMORY;
  556. }
  557. VARIANTCLEAR(vtEmbedProp);
  558. }
  559. }
  560. }
  561. }
  562. }
  563. }
  564. }
  565. catch(_com_error& e)
  566. {
  567. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  568. retCode = PARSER_OUTOFMEMORY;
  569. VARIANTCLEAR(vtEmbedProp);
  570. }
  571. catch(CHeap_Exception)
  572. {
  573. retCode = PARSER_OUTOFMEMORY;
  574. VARIANTCLEAR(vtEmbedProp);
  575. hr = WBEM_E_OUT_OF_MEMORY;
  576. _com_issue_error(hr);
  577. }
  578. return retCode;
  579. }
  580. /*----------------------------------------------------------------------------
  581. Name :ObtainAliasVerbDetails
  582. Synopsis :Obtains the verbs and their details associated with the
  583. alias object and updates the CCommandSwitches of
  584. CParsedInfo object passed to it.
  585. Type :Member Function
  586. Input parameter(s):
  587. rParsedInfo - The parsed info from command line input.
  588. Output parameter(s):
  589. rParsedInfo - The parsed info from command line input.
  590. Return Type :HRESULT
  591. Global Variables :None
  592. Calling Syntax :ObtainAliasVerbDetails(rParsedInfo)
  593. Notes :None
  594. ----------------------------------------------------------------------------*/
  595. HRESULT CCmdAlias::ObtainAliasVerbDetails(CParsedInfo& rParsedInfo)
  596. {
  597. // variables being used in this function.
  598. IWbemClassObject *pIWbemObj = NULL;
  599. IWbemClassObject *pIEmbedObj = NULL;
  600. IWbemClassObject *pIEmbedObj2 = NULL;
  601. HRESULT hr = S_OK;
  602. _TCHAR szNumber[BUFFER512] = NULL_STRING;
  603. DWORD dwThreadId = GetCurrentThreadId();
  604. VARIANT vtVerbs, vtVerbName, vtParameters,
  605. vtParaId, vtParaType, vtVerbType,
  606. vtVerbDerivation, vtDefaultParamValue;
  607. VariantInit(&vtVerbs);
  608. VariantInit(&vtVerbName);
  609. VariantInit(&vtParameters);
  610. VariantInit(&vtParaId);
  611. VariantInit(&vtParaType);
  612. VariantInit(&vtVerbType);
  613. VariantInit(&vtVerbDerivation);
  614. VariantInit(&vtDefaultParamValue);
  615. try
  616. {
  617. CHString chsMsg;
  618. _bstr_t bstrResult;
  619. // Initialize methDetMap each time.
  620. rParsedInfo.GetCmdSwitchesObject().GetMethDetMap().clear();
  621. _bstr_t bstrPath = _bstr_t("MSFT_CliAlias.FriendlyName='") +
  622. _bstr_t(rParsedInfo.GetCmdSwitchesObject().GetAliasName())+
  623. _bstr_t(L"'");
  624. //Retrieving the object from the namespace in m_pIAliasNS
  625. hr = m_pIAliasNS->GetObject(bstrPath, 0, NULL, &pIWbemObj, NULL);
  626. if (m_bTrace || m_eloErrLogOpt)
  627. {
  628. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  629. (WCHAR*) bstrPath);
  630. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  631. dwThreadId, rParsedInfo, m_bTrace);
  632. }
  633. ONFAILTHROWERROR(hr);
  634. // Obtain verb name and method name to get info of verb name
  635. // or method name only if they are specified.
  636. _TCHAR* pVerbName = rParsedInfo.GetCmdSwitchesObject().GetVerbName();
  637. _TCHAR* pMethodName = rParsedInfo.GetCmdSwitchesObject().
  638. GetMethodName();
  639. BOOL bCompareVerb = FALSE, bCompareMethod = FALSE;
  640. if ( pVerbName != NULL &&
  641. CompareTokens(pVerbName,CLI_TOKEN_CALL) &&
  642. pMethodName != NULL )
  643. bCompareMethod = TRUE;
  644. else if ( pVerbName != NULL &&
  645. !CompareTokens(pVerbName,CLI_TOKEN_CALL))
  646. bCompareVerb = TRUE;
  647. // Get "Verbs" property.
  648. hr = pIWbemObj->Get(_bstr_t(L"Verbs"), 0, &vtVerbs, 0, 0) ;
  649. if (m_bTrace || m_eloErrLogOpt)
  650. {
  651. chsMsg.Format(L"IWbemClassObject::Get(L\"Verbs\", 0, -, 0, 0)");
  652. GetBstrTFromVariant(vtVerbs, bstrResult);
  653. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  654. dwThreadId, rParsedInfo, m_bTrace,
  655. 0, bstrResult);
  656. }
  657. ONFAILTHROWERROR(hr);
  658. if ( vtVerbs.vt != VT_EMPTY && vtVerbs.vt != VT_NULL)
  659. {
  660. // Get lower and upper bounds of Verbs array
  661. LONG lUpper = 0, lLower = 0;
  662. hr = SafeArrayGetLBound(vtVerbs.parray, vtVerbs.parray->cDims,
  663. &lLower);
  664. if ( m_eloErrLogOpt )
  665. {
  666. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  667. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  668. dwThreadId, rParsedInfo, FALSE);
  669. }
  670. ONFAILTHROWERROR(hr);
  671. hr = SafeArrayGetUBound(vtVerbs.parray, vtVerbs.parray->cDims,
  672. &lUpper);
  673. if ( m_eloErrLogOpt )
  674. {
  675. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  676. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  677. dwThreadId, rParsedInfo, FALSE);
  678. }
  679. ONFAILTHROWERROR(hr);
  680. for (LONG lIndex = lLower; lIndex <= lUpper; lIndex++)
  681. {
  682. pIEmbedObj = NULL;
  683. // Get "Name" property.
  684. hr = SafeArrayGetElement(vtVerbs.parray,&lIndex,&pIEmbedObj);
  685. if ( m_eloErrLogOpt )
  686. {
  687. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  688. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  689. dwThreadId, rParsedInfo, FALSE);
  690. }
  691. ONFAILTHROWERROR(hr);
  692. hr = pIEmbedObj->Get(_bstr_t(L"Name"),0,&vtVerbName,0,0);
  693. if (m_bTrace || m_eloErrLogOpt)
  694. {
  695. chsMsg.Format(L"IWbemClassObject::Get(L\"Name\", 0, -,"
  696. L"0, 0)");
  697. GetBstrTFromVariant(vtVerbName, bstrResult);
  698. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  699. dwThreadId, rParsedInfo, m_bTrace,
  700. 0, bstrResult);
  701. }
  702. ONFAILTHROWERROR(hr);
  703. // if user defined verb or method is specified then get info
  704. // of only related to user defined or method name.
  705. BOOL bContinue = FALSE;
  706. if ( bCompareMethod == TRUE &&
  707. !CompareTokens(pMethodName,
  708. (_TCHAR*)_bstr_t(vtVerbName.bstrVal) ) )
  709. bContinue = TRUE;
  710. else if ( bCompareVerb == TRUE &&
  711. !CompareTokens(pVerbName,
  712. (_TCHAR*)_bstr_t(vtVerbName.bstrVal)))
  713. bContinue = TRUE;
  714. if ( bContinue == TRUE )
  715. {
  716. SAFEIRELEASE(pIEmbedObj);
  717. continue;
  718. }
  719. _bstr_t bstrDesc;
  720. hr = GetDescOfObject(pIEmbedObj, bstrDesc, rParsedInfo);
  721. ONFAILTHROWERROR(hr);
  722. // Obtaining the input parameters and thier type.
  723. // Get "Parameters" property.
  724. hr = pIEmbedObj->Get(_bstr_t(L"Parameters"),
  725. 0, &vtParameters, 0, 0);
  726. if (m_bTrace || m_eloErrLogOpt)
  727. {
  728. chsMsg.Format(L"IWbemClassObject::Get(L\"Parameters\","
  729. L"0, -, 0, 0)");
  730. GetBstrTFromVariant(vtParameters, bstrResult);
  731. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  732. dwThreadId, rParsedInfo, m_bTrace,
  733. 0, bstrResult);
  734. }
  735. ONFAILTHROWERROR(hr);
  736. if ( vtVerbName.vt != VT_EMPTY && vtVerbName.vt != VT_NULL )
  737. {
  738. if ( bCompareVerb == TRUE || bCompareMethod == TRUE)
  739. {
  740. // Get "VerbType" property.
  741. hr = pIEmbedObj->Get(_bstr_t(L"VerbType"),
  742. 0, &vtVerbType, 0, 0);
  743. if (m_bTrace || m_eloErrLogOpt)
  744. {
  745. chsMsg.Format(L"IWbemClassObject::Get"
  746. L"(L\"VerbType\", 0, -, 0, 0)");
  747. GetBstrTFromVariant(vtVerbType, bstrResult);
  748. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  749. (LPCWSTR)chsMsg, dwThreadId,
  750. rParsedInfo, m_bTrace,
  751. 0, bstrResult );
  752. }
  753. ONFAILTHROWERROR(hr);
  754. if ( vtVerbType.vt == VT_I4 )
  755. {
  756. rParsedInfo.GetCmdSwitchesObject().SetVerbType(
  757. VERBTYPE(V_I4(&vtVerbType)));
  758. }
  759. else
  760. {
  761. rParsedInfo.GetCmdSwitchesObject().SetVerbType(
  762. NONALIAS);
  763. }
  764. // Get "Derivation" property.
  765. hr = pIEmbedObj->Get(_bstr_t(L"Derivation"), 0,
  766. &vtVerbDerivation, 0, 0);
  767. if (m_bTrace || m_eloErrLogOpt)
  768. {
  769. chsMsg.Format(L"IWbemClassObject::Get"
  770. L"(L\"Derivation\", 0, -, 0, 0)");
  771. GetBstrTFromVariant(vtVerbDerivation, bstrResult);
  772. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  773. (LPCWSTR)chsMsg, dwThreadId,
  774. rParsedInfo, m_bTrace,
  775. 0, bstrResult);
  776. }
  777. ONFAILTHROWERROR(hr);
  778. if ( vtVerbDerivation.vt == VT_BSTR )
  779. rParsedInfo.GetCmdSwitchesObject().
  780. SetVerbDerivation(
  781. _bstr_t(vtVerbDerivation.bstrVal));
  782. }
  783. METHODDETAILS mdMethDet;
  784. mdMethDet.Description = bstrDesc;
  785. if ( vtParameters.vt != VT_EMPTY &&
  786. vtParameters.vt != VT_NULL )
  787. {
  788. // Get lower and upper bounds of Descriptions array
  789. LONG lUpper = 0, lLower = 0;
  790. hr = SafeArrayGetLBound(vtParameters.parray,
  791. vtParameters.parray->cDims, &lLower);
  792. if ( m_eloErrLogOpt )
  793. {
  794. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  795. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  796. (LPCWSTR)chsMsg, dwThreadId,
  797. rParsedInfo, FALSE);
  798. }
  799. ONFAILTHROWERROR(hr);
  800. hr = SafeArrayGetUBound(vtParameters.parray,
  801. vtParameters.parray->cDims, &lUpper);
  802. if ( m_eloErrLogOpt )
  803. {
  804. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  805. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  806. (LPCWSTR)chsMsg, dwThreadId,
  807. rParsedInfo, FALSE);
  808. }
  809. ONFAILTHROWERROR(hr);
  810. for (LONG lIndex = lLower; lIndex <= lUpper; lIndex++)
  811. {
  812. hr = SafeArrayGetElement(vtParameters.parray,
  813. &lIndex, &pIEmbedObj2);
  814. if ( m_eloErrLogOpt )
  815. {
  816. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  817. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  818. (LPCWSTR)chsMsg,dwThreadId,
  819. rParsedInfo, FALSE);
  820. }
  821. ONFAILTHROWERROR(hr);
  822. // Get "ParaId" property.
  823. hr = pIEmbedObj2->Get(_bstr_t(L"ParaId"),
  824. 0, &vtParaId, 0, 0);
  825. if (m_bTrace || m_eloErrLogOpt)
  826. {
  827. chsMsg.Format(L"IWbemClassObject::Get"
  828. L"(L\"ParaId\", 0, -, 0, 0)");
  829. GetBstrTFromVariant(vtParaId, bstrResult);
  830. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  831. (LPCWSTR)chsMsg,dwThreadId,
  832. rParsedInfo, m_bTrace,
  833. 0, bstrResult);
  834. }
  835. ONFAILTHROWERROR(hr);
  836. // Get "Type" property.
  837. hr = pIEmbedObj2->Get(_bstr_t(L"Type"), 0,
  838. &vtParaType, 0, 0);
  839. if (m_bTrace || m_eloErrLogOpt)
  840. {
  841. chsMsg.Format(L"IWbemClassObject::Get"
  842. L"(L\"Type\", 0, -, 0, 0)");
  843. GetBstrTFromVariant(vtParaType, bstrResult);
  844. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  845. (LPCWSTR)chsMsg,dwThreadId,
  846. rParsedInfo, m_bTrace,
  847. 0, bstrResult);
  848. }
  849. ONFAILTHROWERROR(hr);
  850. // Get "Default" property.
  851. hr = pIEmbedObj2->Get(_bstr_t(L"Default"), 0,
  852. &vtDefaultParamValue, 0, 0);
  853. if (m_bTrace || m_eloErrLogOpt)
  854. {
  855. chsMsg.Format(L"IWbemClassObject::Get"
  856. L"(L\"Default\", 0, -, 0, 0)");
  857. GetBstrTFromVariant(vtDefaultParamValue,
  858. bstrResult);
  859. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  860. (LPCWSTR)chsMsg,dwThreadId,
  861. rParsedInfo, m_bTrace,
  862. 0, bstrResult);
  863. }
  864. ONFAILTHROWERROR(hr);
  865. if ( vtParaId.vt != VT_EMPTY &&
  866. vtParaId.vt != VT_NULL )
  867. {
  868. PROPERTYDETAILS pdPropDet;
  869. pdPropDet.InOrOut = UNKNOWN;
  870. hr = GetQualifiers(pIEmbedObj2, pdPropDet,
  871. rParsedInfo);
  872. if ( vtParaType.vt == VT_BSTR )
  873. pdPropDet.Type = vtParaType.bstrVal;
  874. else
  875. pdPropDet.Type = _bstr_t("Not Available");
  876. if ( vtDefaultParamValue.vt == VT_BSTR )
  877. pdPropDet.Default = vtDefaultParamValue.
  878. bstrVal;
  879. // Making bstrPropName begin with numbers to
  880. // maintain the order of method arguments in
  881. // map. while displaying remove numbers and
  882. // display the parameters in case of help only
  883. // Also for named paramlist and cmdline
  884. // utility processing.
  885. _bstr_t bstrNumberedPropName;
  886. if ( rParsedInfo.GetGlblSwitchesObject().
  887. GetHelpFlag() ||
  888. rParsedInfo.GetCmdSwitchesObject().
  889. GetVerbType() == CMDLINE )
  890. {
  891. _TCHAR szMsg[BUFFER512];
  892. _ltot(lIndex, szNumber, 10);
  893. _stprintf(szMsg, _T("%-5s"), szNumber);
  894. bstrNumberedPropName = _bstr_t(szMsg) +
  895. _bstr_t(vtParaId.bstrVal);
  896. }
  897. else
  898. bstrNumberedPropName =
  899. _bstr_t(vtParaId.bstrVal);
  900. mdMethDet.Params.insert(
  901. PROPDETMAP::value_type(
  902. bstrNumberedPropName, pdPropDet));
  903. }
  904. VARIANTCLEAR(vtParaId);
  905. VARIANTCLEAR(vtParaType);
  906. VARIANTCLEAR(vtDefaultParamValue);
  907. SAFEIRELEASE(pIEmbedObj2);
  908. }
  909. }
  910. rParsedInfo.GetCmdSwitchesObject().AddToMethDetMap
  911. (vtVerbName.bstrVal, mdMethDet);
  912. }
  913. VARIANTCLEAR(vtVerbName);
  914. VARIANTCLEAR(vtVerbType);
  915. VARIANTCLEAR(vtVerbDerivation);
  916. VARIANTCLEAR(vtParameters);
  917. SAFEIRELEASE(pIEmbedObj);
  918. if ( bCompareVerb == TRUE || bCompareMethod == TRUE)
  919. break;
  920. }
  921. }
  922. VARIANTCLEAR(vtVerbs);
  923. SAFEIRELEASE(pIWbemObj);
  924. }
  925. catch(_com_error& e)
  926. {
  927. SAFEIRELEASE(pIWbemObj);
  928. SAFEIRELEASE(pIEmbedObj);
  929. VARIANTCLEAR(vtVerbs);
  930. VARIANTCLEAR(vtVerbName);
  931. VARIANTCLEAR(vtVerbType);
  932. VARIANTCLEAR(vtVerbDerivation);
  933. VARIANTCLEAR(vtDefaultParamValue);
  934. hr = e.Error();
  935. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  936. }
  937. catch(CHeap_Exception)
  938. {
  939. SAFEIRELEASE(pIWbemObj);
  940. SAFEIRELEASE(pIEmbedObj);
  941. VARIANTCLEAR(vtVerbs);
  942. VARIANTCLEAR(vtVerbName);
  943. VARIANTCLEAR(vtVerbType);
  944. VARIANTCLEAR(vtVerbDerivation);
  945. VARIANTCLEAR(vtDefaultParamValue);
  946. hr = WBEM_E_OUT_OF_MEMORY;
  947. _com_issue_error(hr);
  948. }
  949. return hr;
  950. }
  951. /*----------------------------------------------------------------------------
  952. Name :ObtainAliasFriendlyNames
  953. Synopsis :Obtains all the Friendly Names and descriptions in the
  954. CmdAlias and updates it in the CCommandSwitches of
  955. CParsedInfo object passed to it.
  956. Type :Member Function
  957. Input parameter(s):
  958. rParsedInfo - The parsed info from command line input.
  959. Output parameter(s):
  960. rParsedInfo - The parsed info from command line input.
  961. Return Type :HRESULT
  962. Global Variables :None
  963. Calling Syntax :ObtainAliasFriendlyNames(rParsedInfo)
  964. Notes :None
  965. ----------------------------------------------------------------------------*/
  966. HRESULT CCmdAlias::ObtainAliasFriendlyNames(CParsedInfo& rParsedInfo)
  967. {
  968. // variables being used in this function.
  969. HRESULT hr = S_OK;
  970. IEnumWbemClassObject *pIEnumObj = NULL;
  971. IWbemClassObject *pIWbemObj = NULL;
  972. DWORD dwThreadId = GetCurrentThreadId();
  973. VARIANT vtName;
  974. VariantInit(&vtName);
  975. try
  976. {
  977. CHString chsMsg;
  978. _bstr_t bstrResult;
  979. // Get alias object
  980. hr = m_pIAliasNS->ExecQuery(_bstr_t(L"WQL"),
  981. _bstr_t(L"SELECT * FROM MSFT_CliAlias"),
  982. WBEM_FLAG_FORWARD_ONLY|
  983. WBEM_FLAG_RETURN_IMMEDIATELY,
  984. NULL, &pIEnumObj);
  985. if (m_bTrace || m_eloErrLogOpt)
  986. {
  987. chsMsg.Format(L"IWbemServices::ExecQuery(L\"WQL\","
  988. L"L\"SELECT * FROM MSFT_CliAlias\","
  989. L"WBEM_FLAG_FORWARD_ONLY|WBEM_FLAG_RETURN_IMMEDIATELY,"
  990. L"NULL, -)");
  991. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  992. dwThreadId, rParsedInfo, m_bTrace);
  993. }
  994. ONFAILTHROWERROR(hr);
  995. // Set the security
  996. hr = SetSecurity(pIEnumObj, NULL, NULL, NULL, NULL,
  997. rParsedInfo.GetGlblSwitchesObject().GetAuthenticationLevel(),
  998. rParsedInfo.GetGlblSwitchesObject().GetImpersonationLevel());
  999. if (m_bTrace || m_eloErrLogOpt)
  1000. {
  1001. chsMsg.Format(
  1002. L"CoSetProxyBlanket(-, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,"
  1003. L"NULL, %d, %d, -, EOAC_NONE)",
  1004. rParsedInfo.GetGlblSwitchesObject().GetAuthenticationLevel(),
  1005. rParsedInfo.GetGlblSwitchesObject().GetImpersonationLevel());
  1006. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1007. dwThreadId, rParsedInfo, m_bTrace);
  1008. }
  1009. ONFAILTHROWERROR(hr);
  1010. ULONG ulReturned = 0;
  1011. // Obtain the object starting at the current position in the
  1012. // enumeration and loop through the instance list.
  1013. while(((hr=pIEnumObj->Next(WBEM_INFINITE,1,&pIWbemObj,&ulReturned))==
  1014. S_OK) && (ulReturned == 1))
  1015. {
  1016. VariantInit(&vtName);
  1017. // Gets "FriendlyName" array property of alias object
  1018. hr = pIWbemObj->Get(_bstr_t(L"FriendlyName"), 0, &vtName, 0, 0);
  1019. if (m_bTrace || m_eloErrLogOpt)
  1020. {
  1021. chsMsg.Format(L"IWbemClassObject::Get(L\"FriendlyName\", 0,"
  1022. L"-, 0, 0)");
  1023. GetBstrTFromVariant(vtName, bstrResult);
  1024. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1025. dwThreadId, rParsedInfo, m_bTrace,
  1026. 0, bstrResult);
  1027. }
  1028. ONFAILTHROWERROR(hr);
  1029. if (vtName.vt != VT_NULL && vtName.vt != VT_EMPTY)
  1030. {
  1031. _bstr_t bstrFriendlyName = vtName.bstrVal;
  1032. _bstr_t bstrDesc;
  1033. hr = GetDescOfObject(pIWbemObj, bstrDesc, rParsedInfo, TRUE);
  1034. ONFAILTHROWERROR(hr);
  1035. //Add the "FriendlyName" to FriendlyName Map
  1036. rParsedInfo.GetCmdSwitchesObject().
  1037. AddToAlsFrnNmsOrTrnsTblMap(CharUpper(bstrFriendlyName)
  1038. ,bstrDesc);
  1039. }
  1040. VARIANTCLEAR(vtName);
  1041. SAFEIRELEASE(pIWbemObj);
  1042. }
  1043. SAFEIRELEASE(pIEnumObj);
  1044. }
  1045. catch(_com_error& e)
  1046. {
  1047. SAFEIRELEASE(pIEnumObj);
  1048. SAFEIRELEASE(pIWbemObj);
  1049. VARIANTCLEAR(vtName);
  1050. hr = e.Error();
  1051. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  1052. }
  1053. catch(CHeap_Exception)
  1054. {
  1055. SAFEIRELEASE(pIEnumObj);
  1056. SAFEIRELEASE(pIWbemObj);
  1057. VARIANTCLEAR(vtName);
  1058. hr = WBEM_E_OUT_OF_MEMORY;
  1059. _com_issue_error(hr);
  1060. }
  1061. return hr;
  1062. }
  1063. /*----------------------------------------------------------------------------
  1064. Name :ObtainAliasFormat
  1065. Synopsis :Obtains the Derivation of the properties for the Format
  1066. associated with the alias object and updates the
  1067. CCommandSwitches of CParsedInfo object passed to it.
  1068. Type :Member Function
  1069. Input parameter(s):
  1070. rParsedInfo - The parsed info from command line input.
  1071. Output parameter(s):
  1072. rParsedInfo - The parsed info from command line input.
  1073. Return Type :BOOL : TRUE - if valid format is not present
  1074. FALSE - if invalid format
  1075. Global Variables :None
  1076. Calling Syntax :ObtainAliasFormat(rParsedInfo)
  1077. Notes :If bCheckForListFrmsAvail == TRUE then functions checks
  1078. only for availibilty of list formats with the alias.
  1079. ----------------------------------------------------------------------------*/
  1080. BOOL CCmdAlias::ObtainAliasFormat(CParsedInfo& rParsedInfo,
  1081. BOOL bCheckForListFrmsAvail)
  1082. {
  1083. // variables being used in this function.
  1084. HRESULT hr = S_OK;
  1085. IWbemClassObject *pIWbemObj = NULL;
  1086. IWbemClassObject *pIEmbedObj = NULL;
  1087. IWbemClassObject *pIEmbedObj2 = NULL;
  1088. BOOL bExist = FALSE;
  1089. DWORD dwThreadId = GetCurrentThreadId();
  1090. VARIANT vtFormats, vtFormatName,
  1091. vtProperties, vtPropertyName, vtPropertyDerivation ;
  1092. BOOL bHelp = rParsedInfo.
  1093. GetGlblSwitchesObject().
  1094. GetHelpFlag();
  1095. // Initializing all Variants variables being used in this function.
  1096. VariantInit(&vtFormats);
  1097. VariantInit(&vtFormatName);
  1098. VariantInit(&vtProperties);
  1099. VariantInit(&vtPropertyName);
  1100. VariantInit(&vtPropertyDerivation);
  1101. try
  1102. {
  1103. CHString chsMsg;
  1104. _bstr_t bstrResult;
  1105. _bstr_t bstrPath = _bstr_t("MSFT_CliAlias.FriendlyName='") +
  1106. _bstr_t(rParsedInfo.GetCmdSwitchesObject().GetAliasName())+
  1107. _bstr_t(L"'");
  1108. // Get alias object
  1109. hr = m_pIAliasNS->GetObject(bstrPath, 0, NULL, &pIWbemObj, NULL);
  1110. if (m_bTrace || m_eloErrLogOpt)
  1111. {
  1112. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  1113. (WCHAR*) bstrPath);
  1114. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1115. dwThreadId, rParsedInfo, m_bTrace);
  1116. }
  1117. ONFAILTHROWERROR(hr);
  1118. // Get Formats array property of alias object
  1119. hr = pIWbemObj->Get(_bstr_t(L"Formats"), 0, &vtFormats, 0, 0);
  1120. if (m_bTrace || m_eloErrLogOpt)
  1121. {
  1122. chsMsg.Format(L"IWbemClassObject::Get(L\"Formats\", 0, -,0, 0)");
  1123. GetBstrTFromVariant(vtFormats, bstrResult);
  1124. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1125. dwThreadId, rParsedInfo, m_bTrace,
  1126. 0, bstrResult);
  1127. }
  1128. ONFAILTHROWERROR(hr);
  1129. if ( vtFormats.vt != VT_NULL && vtFormats.vt != VT_EMPTY
  1130. && bCheckForListFrmsAvail == FALSE)
  1131. {
  1132. // Get lower and upper bounds of Formats array
  1133. LONG lUpper = 0, lLower = 0;
  1134. hr = SafeArrayGetLBound(vtFormats.parray, vtFormats.parray->cDims,
  1135. &lLower);
  1136. if ( m_eloErrLogOpt )
  1137. {
  1138. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  1139. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1140. dwThreadId, rParsedInfo, FALSE);
  1141. }
  1142. ONFAILTHROWERROR(hr);
  1143. hr = SafeArrayGetUBound(vtFormats.parray, vtFormats.parray->cDims,
  1144. &lUpper);
  1145. if ( m_eloErrLogOpt )
  1146. {
  1147. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  1148. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1149. dwThreadId, rParsedInfo, FALSE);
  1150. }
  1151. ONFAILTHROWERROR(hr);
  1152. // Iterate through the Formats array property
  1153. for (LONG lIndex = lLower; lIndex <= lUpper; lIndex++)
  1154. {
  1155. // Get this property.
  1156. hr =SafeArrayGetElement(vtFormats.parray,&lIndex,&pIEmbedObj);
  1157. if ( m_eloErrLogOpt )
  1158. {
  1159. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  1160. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  1161. dwThreadId, rParsedInfo, FALSE);
  1162. }
  1163. ONFAILTHROWERROR(hr);
  1164. hr = pIEmbedObj->Get(_bstr_t(L"Name"),0,&vtFormatName,0,0);
  1165. if (m_bTrace || m_eloErrLogOpt)
  1166. {
  1167. chsMsg.Format(L"IWbemClassObject::Get(L\"Name\", 0,"
  1168. L"-, 0, 0)");
  1169. GetBstrTFromVariant(vtFormatName, bstrResult);
  1170. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  1171. dwThreadId, rParsedInfo, m_bTrace,
  1172. 0, bstrResult);
  1173. }
  1174. ONFAILTHROWERROR(hr);
  1175. //Comparing the specified Format in the alias against the
  1176. //formats available for the specified alias.
  1177. if(CompareTokens(_bstr_t(rParsedInfo.GetCmdSwitchesObject().
  1178. GetListFormat()), _bstr_t(vtFormatName.bstrVal)))
  1179. {
  1180. bExist = TRUE;
  1181. VARIANT vtFormat;
  1182. VariantInit(&vtFormat);
  1183. //Getting the "Format" property.
  1184. hr = pIEmbedObj->Get(_bstr_t(L"Format"),0,
  1185. &vtFormat, 0, 0);
  1186. if (m_bTrace || m_eloErrLogOpt)
  1187. {
  1188. chsMsg.Format( L"IWbemClassObject::Get(L\"Format\","
  1189. L"0, -, 0, 0)");
  1190. GetBstrTFromVariant(vtFormat, bstrResult);
  1191. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1192. (LPCWSTR)chsMsg, dwThreadId,
  1193. rParsedInfo, m_bTrace,
  1194. 0, bstrResult);
  1195. }
  1196. ONFAILTHROWERROR(hr);
  1197. if ( vtFormat.vt != VT_EMPTY && vtFormat.vt != VT_NULL )
  1198. {
  1199. if (rParsedInfo.GetCmdSwitchesObject().
  1200. GetXSLTDetailsVector().empty())
  1201. {
  1202. _bstr_t bstrFileName ;
  1203. // If _T("") is the value, it should be treated as
  1204. // equivalent to <empty>
  1205. if (CompareTokens(vtFormat.bstrVal, _T("")))
  1206. {
  1207. bstrFileName = _bstr_t(CLI_TOKEN_TABLE);
  1208. }
  1209. else
  1210. {
  1211. bstrFileName = _bstr_t(vtFormat.bstrVal);
  1212. }
  1213. g_wmiCmd.GetFileFromKey(bstrFileName, bstrFileName);
  1214. XSLTDET xdXSLTDet;
  1215. xdXSLTDet.FileName = bstrFileName;
  1216. FrameFileAndAddToXSLTDetVector(xdXSLTDet,
  1217. rParsedInfo);
  1218. }
  1219. }
  1220. VariantClear(&vtFormat);
  1221. //Getting the "Properties" property.
  1222. hr=pIEmbedObj->Get(_bstr_t(L"Properties"),
  1223. 0, &vtProperties, 0, 0);
  1224. if (m_bTrace || m_eloErrLogOpt)
  1225. {
  1226. chsMsg.Format(L"IWbemClassObject::Get(L\"Properties\","
  1227. L"0, -, 0, 0)");
  1228. GetBstrTFromVariant(vtProperties, bstrResult);
  1229. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1230. (LPCWSTR)chsMsg, dwThreadId,
  1231. rParsedInfo, m_bTrace,
  1232. 0, bstrResult);
  1233. }
  1234. ONFAILTHROWERROR(hr);
  1235. if ( vtProperties.vt != VT_NULL )
  1236. {
  1237. LONG lILower = 0, lIUpper = 0;
  1238. hr = SafeArrayGetLBound(vtProperties.parray,
  1239. vtProperties.parray->cDims, &lILower);
  1240. if ( m_eloErrLogOpt )
  1241. {
  1242. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  1243. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1244. (LPCWSTR)chsMsg, dwThreadId,
  1245. rParsedInfo, FALSE);
  1246. }
  1247. ONFAILTHROWERROR(hr);
  1248. hr = SafeArrayGetUBound(vtProperties.parray,
  1249. vtProperties.parray->cDims, &lIUpper);
  1250. if ( m_eloErrLogOpt )
  1251. {
  1252. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  1253. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1254. (LPCWSTR)chsMsg, dwThreadId,
  1255. rParsedInfo, FALSE);
  1256. }
  1257. ONFAILTHROWERROR(hr);
  1258. // Iterate through the Properties array property
  1259. for(LONG lIIndex = lILower;
  1260. lIIndex <= lIUpper;
  1261. lIIndex++)
  1262. {
  1263. // Get this property.
  1264. hr = SafeArrayGetElement(vtProperties.parray,
  1265. &lIIndex, &pIEmbedObj2);
  1266. if ( m_eloErrLogOpt )
  1267. {
  1268. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  1269. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1270. (LPCWSTR)chsMsg, dwThreadId,
  1271. rParsedInfo, FALSE);
  1272. }
  1273. ONFAILTHROWERROR(hr);
  1274. //Getting the "Name" property
  1275. hr = pIEmbedObj2->Get(_bstr_t(L"Name"), 0,
  1276. &vtPropertyName,0,0);
  1277. if (m_bTrace || m_eloErrLogOpt)
  1278. {
  1279. chsMsg.Format(L"IWbemClassObject::Get"
  1280. L"(L\"Name\", 0, -, 0, 0)");
  1281. GetBstrTFromVariant(vtPropertyName,
  1282. bstrResult);
  1283. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1284. (LPCWSTR)chsMsg, dwThreadId,
  1285. rParsedInfo, m_bTrace,
  1286. 0, bstrResult);
  1287. }
  1288. ONFAILTHROWERROR(hr);
  1289. //Getting the "Derivation" property
  1290. hr = pIEmbedObj2->Get(_bstr_t(L"Derivation"), 0,
  1291. &vtPropertyDerivation,0,0);
  1292. if (m_bTrace || m_eloErrLogOpt)
  1293. {
  1294. chsMsg.Format(L"IWbemClassObject::Get"
  1295. L"(L\"Derivation\", 0, -, 0, 0)");
  1296. GetBstrTFromVariant(vtPropertyDerivation,
  1297. bstrResult);
  1298. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1299. (LPCWSTR)chsMsg, dwThreadId,
  1300. rParsedInfo, m_bTrace,
  1301. 0, bstrResult);
  1302. }
  1303. ONFAILTHROWERROR(hr);
  1304. _bstr_t bstrPropName;
  1305. if ( bHelp )
  1306. {
  1307. if ( vtPropertyName.vt == VT_BSTR )
  1308. bstrPropName = vtPropertyName.bstrVal;
  1309. }
  1310. else
  1311. {
  1312. if ( vtPropertyDerivation.vt == VT_BSTR )
  1313. bstrPropName = vtPropertyDerivation.bstrVal;
  1314. else if ( vtPropertyName.vt == VT_BSTR )
  1315. bstrPropName = vtPropertyName.bstrVal;
  1316. }
  1317. //Add propertyderivation to property list in
  1318. // rParsedInfo
  1319. if((!bstrPropName == FALSE) &&
  1320. !rParsedInfo.GetCmdSwitchesObject().
  1321. AddToPropertyList(
  1322. (_TCHAR*)bstrPropName))
  1323. {
  1324. rParsedInfo.GetCmdSwitchesObject().
  1325. SetErrataCode(OUT_OF_MEMORY);
  1326. bExist = FALSE;
  1327. VARIANTCLEAR(vtPropertyDerivation);
  1328. break;
  1329. }
  1330. // Add propertyname to property list in
  1331. // rParsedInfo only to avail information of Name
  1332. // and Derivation of list properties for XML
  1333. // logging.
  1334. PROPERTYDETAILS pdPropDet;
  1335. if ( vtPropertyDerivation.vt == VT_BSTR )
  1336. pdPropDet.Derivation =
  1337. vtPropertyDerivation.bstrVal;
  1338. else
  1339. pdPropDet.Derivation = _bstr_t(TOKEN_NA);
  1340. rParsedInfo.GetCmdSwitchesObject().
  1341. AddToPropDetMap(
  1342. vtPropertyName.bstrVal, pdPropDet);
  1343. VARIANTCLEAR(vtPropertyName);
  1344. VARIANTCLEAR(vtPropertyDerivation);
  1345. // Release pIEmbedObj2
  1346. SAFEIRELEASE(pIEmbedObj2);
  1347. }
  1348. }
  1349. // Release memory held by vtProperties
  1350. VARIANTCLEAR(vtProperties);
  1351. // Free memory held by vtFormatName
  1352. VARIANTCLEAR(vtFormatName);
  1353. // Release pIEmbedObj
  1354. SAFEIRELEASE(pIEmbedObj);
  1355. break;
  1356. }
  1357. // Free memory held by vtFormatName
  1358. VARIANTCLEAR(vtFormatName);
  1359. // Release pIEmbedObj
  1360. SAFEIRELEASE(pIEmbedObj);
  1361. }
  1362. // Release memory held by vtFormats
  1363. VARIANTCLEAR(vtFormats);
  1364. }
  1365. else if ( vtFormats.vt != VT_NULL && vtFormats.vt != VT_EMPTY )
  1366. {
  1367. bExist = TRUE;
  1368. }
  1369. // Release pIWbem object
  1370. SAFEIRELEASE(pIWbemObj);
  1371. }
  1372. catch(_com_error& e)
  1373. {
  1374. SAFEIRELEASE(pIWbemObj);
  1375. SAFEIRELEASE(pIEmbedObj);
  1376. SAFEIRELEASE(pIEmbedObj2);
  1377. VARIANTCLEAR(vtFormats);
  1378. VARIANTCLEAR(vtFormatName);
  1379. VARIANTCLEAR(vtProperties);
  1380. VARIANTCLEAR(vtPropertyName);
  1381. VARIANTCLEAR(vtPropertyDerivation);
  1382. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  1383. bExist = FALSE;
  1384. }
  1385. catch(CHeap_Exception)
  1386. {
  1387. SAFEIRELEASE(pIWbemObj);
  1388. SAFEIRELEASE(pIEmbedObj);
  1389. SAFEIRELEASE(pIEmbedObj2);
  1390. VARIANTCLEAR(vtFormats);
  1391. VARIANTCLEAR(vtFormatName);
  1392. VARIANTCLEAR(vtProperties);
  1393. VARIANTCLEAR(vtPropertyName);
  1394. VARIANTCLEAR(vtPropertyDerivation);
  1395. bExist = FALSE;
  1396. hr = WBEM_E_OUT_OF_MEMORY;
  1397. _com_issue_error(hr);
  1398. }
  1399. return bExist;
  1400. }
  1401. /*----------------------------------------------------------------------------
  1402. Name :ObtainAliasPropDetails
  1403. Synopsis :Obtains the details of the properties for the Format
  1404. associated with the alias object and updates the
  1405. CCommandSwitches of CParsedInfo object passed to it.
  1406. Type :Member Function
  1407. Input parameter(s):
  1408. rParsedInfo - The parsed info from command line input.
  1409. Output parameter(s):
  1410. rParsedInfo - The parsed info from command line input.
  1411. Return Type :HRESULT
  1412. Global Variables :None
  1413. Calling Syntax :ObtainAliasPropDetails(rParsedInfo)
  1414. Notes :pbCheckWritePropsAvailInAndOut == TRUE then function
  1415. checks for availibility of properties and returns in
  1416. the same pbCheckWritePropsAvailInAndOut parameter.
  1417. pbCheckFULLPropsAvailInAndOut == TRUE then function
  1418. checks for availibility of alias properties i.e in FULL
  1419. list format.
  1420. Imp : Any one of the input pointers can only be
  1421. specified.
  1422. ----------------------------------------------------------------------------*/
  1423. HRESULT CCmdAlias::ObtainAliasPropDetails(CParsedInfo& rParsedInfo,
  1424. BOOL *pbCheckWritePropsAvailInAndOut,
  1425. BOOL *pbCheckFULLPropsAvailInAndOut)
  1426. {
  1427. // variables being used in this function.
  1428. HRESULT hr = S_OK;
  1429. IWbemClassObject *pIWbemObj = NULL;
  1430. IWbemClassObject *pIEmbedObj = NULL;
  1431. IWbemClassObject *pIEmbedObj2 = NULL;
  1432. BOOL bPropList = FALSE;
  1433. _TCHAR *pszVerbName = NULL;
  1434. DWORD dwThreadId = GetCurrentThreadId();
  1435. VARIANT vtFormats, vtFormatName,
  1436. vtProperties, vtPropertyName, vtPropertyDerivation;
  1437. // Initializing all Variants variables being used in this function.
  1438. VariantInit(&vtFormats);
  1439. VariantInit(&vtFormatName);
  1440. VariantInit(&vtProperties);
  1441. VariantInit(&vtPropertyName);
  1442. VariantInit(&vtPropertyDerivation);
  1443. CHARVECTOR cvPropList;
  1444. if ( pbCheckWritePropsAvailInAndOut != NULL )
  1445. *pbCheckWritePropsAvailInAndOut = FALSE;
  1446. if ( pbCheckFULLPropsAvailInAndOut != NULL )
  1447. *pbCheckFULLPropsAvailInAndOut = FALSE;
  1448. try
  1449. {
  1450. CHString chsMsg;
  1451. _bstr_t bstrResult;
  1452. pszVerbName = rParsedInfo.GetCmdSwitchesObject().GetVerbName();
  1453. cvPropList = rParsedInfo.GetCmdSwitchesObject().GetPropertyList();
  1454. if ( cvPropList.size() != 0 )
  1455. bPropList = TRUE;
  1456. _bstr_t bstrPath = _bstr_t("MSFT_CliAlias.FriendlyName='") +
  1457. _bstr_t(rParsedInfo.GetCmdSwitchesObject().GetAliasName())+
  1458. _bstr_t(L"'");
  1459. // Get alias object
  1460. hr = m_pIAliasNS->GetObject(bstrPath, 0, NULL, &pIWbemObj, NULL);
  1461. if (m_bTrace || m_eloErrLogOpt)
  1462. {
  1463. chsMsg.Format( L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  1464. (WCHAR*) bstrPath);
  1465. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1466. dwThreadId, rParsedInfo, m_bTrace);
  1467. }
  1468. ONFAILTHROWERROR(hr);
  1469. // Get Formats array property of alias object
  1470. hr = pIWbemObj->Get(_bstr_t(L"Formats"), 0, &vtFormats, 0, 0);
  1471. if (m_bTrace || m_eloErrLogOpt)
  1472. {
  1473. chsMsg.Format(L"IWbemClassObject::Get(L\"Formats\", 0,"
  1474. L"-, 0, 0)");
  1475. GetBstrTFromVariant(vtFormats, bstrResult);
  1476. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1477. dwThreadId, rParsedInfo, m_bTrace,
  1478. 0, bstrResult);
  1479. }
  1480. ONFAILTHROWERROR(hr);
  1481. BOOL bSetVerb = pszVerbName != NULL &&
  1482. CompareTokens(pszVerbName,CLI_TOKEN_SET);
  1483. if ( vtFormats.vt != VT_NULL && vtFormats.vt != VT_EMPTY )
  1484. {
  1485. // Get lower and upper bounds of Formats array
  1486. LONG lUpper = 0, lLower = 0;
  1487. hr = SafeArrayGetLBound(vtFormats.parray, vtFormats.parray->cDims,
  1488. &lLower);
  1489. if ( m_eloErrLogOpt )
  1490. {
  1491. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  1492. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1493. dwThreadId, rParsedInfo, FALSE);
  1494. }
  1495. ONFAILTHROWERROR(hr);
  1496. hr = SafeArrayGetUBound(vtFormats.parray,vtFormats.parray->cDims,
  1497. &lUpper);
  1498. if ( m_eloErrLogOpt )
  1499. {
  1500. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  1501. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1502. dwThreadId, rParsedInfo, FALSE);
  1503. }
  1504. ONFAILTHROWERROR(hr);
  1505. // Iterate through the Formats array property
  1506. for (LONG lIndex = lLower; lIndex <= lUpper; lIndex++)
  1507. {
  1508. // Get this property.
  1509. hr=SafeArrayGetElement(vtFormats.parray,&lIndex,&pIEmbedObj);
  1510. if ( m_eloErrLogOpt )
  1511. {
  1512. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  1513. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  1514. dwThreadId, rParsedInfo, FALSE);
  1515. }
  1516. ONFAILTHROWERROR(hr);
  1517. hr = pIEmbedObj->Get(_bstr_t(L"Name"),0,&vtFormatName,0,0);
  1518. if (m_bTrace || m_eloErrLogOpt)
  1519. {
  1520. chsMsg.Format(L"IWbemClassObject::Get(L\"Name\", 0,"
  1521. L"-, 0, 0)");
  1522. GetBstrTFromVariant(vtFormatName, bstrResult);
  1523. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  1524. dwThreadId, rParsedInfo, m_bTrace,
  1525. 0, bstrResult);
  1526. }
  1527. ONFAILTHROWERROR(hr);
  1528. BOOL bGetProps = FALSE;
  1529. if ( pbCheckWritePropsAvailInAndOut != NULL)
  1530. bGetProps = CompareTokens(_bstr_t(vtFormatName.bstrVal),
  1531. _T("WRITEABLE"));
  1532. else if ( pbCheckFULLPropsAvailInAndOut != NULL)
  1533. bGetProps = CompareTokens(_bstr_t(vtFormatName.bstrVal),
  1534. _T("FULL"));
  1535. else
  1536. {
  1537. bGetProps = (bSetVerb) ?
  1538. ((rParsedInfo.GetHelpInfoObject().GetHelp(SETVerb)) ?
  1539. CompareTokens(_bstr_t(vtFormatName.bstrVal),
  1540. _T("WRITEABLE")):
  1541. CompareTokens(_bstr_t(vtFormatName.bstrVal),
  1542. _T("FULL")) ):
  1543. CompareTokens(_bstr_t(vtFormatName.bstrVal),_T("FULL"));
  1544. }
  1545. //Comparing the specified Format in the alias against
  1546. //the formats available for the specified alias.
  1547. if( bGetProps )
  1548. {
  1549. //Getting the "Properties" property.
  1550. hr=pIEmbedObj->Get(_bstr_t(L"Properties"),0,
  1551. &vtProperties, 0, 0);
  1552. if (m_bTrace || m_eloErrLogOpt)
  1553. {
  1554. chsMsg.Format(L"IWbemClassObject::Get"
  1555. L"(L\"Properties\", 0, -, 0, 0)");
  1556. GetBstrTFromVariant(vtProperties, bstrResult);
  1557. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1558. (LPCWSTR)chsMsg, dwThreadId,
  1559. rParsedInfo, m_bTrace,
  1560. 0, bstrResult);
  1561. }
  1562. ONFAILTHROWERROR(hr);
  1563. if ( vtProperties.vt != VT_NULL )
  1564. {
  1565. LONG lILower = 0, lIUpper = 0;
  1566. hr = SafeArrayGetLBound(vtProperties.parray,
  1567. vtProperties.parray->cDims, &lILower);
  1568. if ( m_eloErrLogOpt )
  1569. {
  1570. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  1571. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1572. (LPCWSTR)chsMsg, dwThreadId,
  1573. rParsedInfo, FALSE);
  1574. }
  1575. ONFAILTHROWERROR(hr);
  1576. hr = SafeArrayGetUBound(vtProperties.parray,
  1577. vtProperties.parray->cDims, &lIUpper);
  1578. if ( m_eloErrLogOpt )
  1579. {
  1580. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  1581. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1582. (LPCWSTR)chsMsg, dwThreadId,
  1583. rParsedInfo, FALSE);
  1584. }
  1585. ONFAILTHROWERROR(hr);
  1586. // Iterate through the Properties array property
  1587. for(LONG lIIndex=lILower; lIIndex<=lIUpper; lIIndex++)
  1588. {
  1589. // Get this property.
  1590. hr = SafeArrayGetElement(vtProperties.parray,
  1591. &lIIndex, &pIEmbedObj2);
  1592. if ( m_eloErrLogOpt )
  1593. {
  1594. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  1595. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1596. (LPCWSTR)chsMsg,dwThreadId,
  1597. rParsedInfo, FALSE);
  1598. }
  1599. ONFAILTHROWERROR(hr);
  1600. //Getting the "Name" property
  1601. hr = pIEmbedObj2->Get(_bstr_t(L"Name"), 0,
  1602. &vtPropertyName,0,0);
  1603. if (m_bTrace || m_eloErrLogOpt)
  1604. {
  1605. chsMsg.Format(L"IWbemClassObject::Get"
  1606. L"(L\"Name\", 0, -, 0, 0)");
  1607. GetBstrTFromVariant(vtPropertyName,
  1608. bstrResult);
  1609. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1610. (LPCWSTR)chsMsg,dwThreadId,
  1611. rParsedInfo, m_bTrace,
  1612. 0, bstrResult);
  1613. }
  1614. ONFAILTHROWERROR(hr);
  1615. //Getting the "Derivation" property
  1616. hr = pIEmbedObj2->Get(_bstr_t(L"Derivation"), 0,
  1617. &vtPropertyDerivation,0,0);
  1618. if (m_bTrace || m_eloErrLogOpt)
  1619. {
  1620. chsMsg.Format(L"IWbemClassObject::Get"
  1621. L"(L\"Derivation\", 0, -, 0, 0)");
  1622. GetBstrTFromVariant(vtPropertyDerivation,
  1623. bstrResult);
  1624. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1625. (LPCWSTR)chsMsg,dwThreadId,
  1626. rParsedInfo, m_bTrace,
  1627. 0, bstrResult);
  1628. }
  1629. ONFAILTHROWERROR(hr);
  1630. if (vtPropertyName.vt == VT_BSTR)
  1631. {
  1632. CHARVECTOR::iterator tempIterator;
  1633. if ( bPropList == TRUE &&
  1634. !Find(cvPropList,
  1635. _bstr_t(vtPropertyName.bstrVal),
  1636. tempIterator) )
  1637. {
  1638. SAFEIRELEASE(pIEmbedObj2)
  1639. continue;
  1640. }
  1641. if ( pbCheckWritePropsAvailInAndOut != NULL)
  1642. {
  1643. *pbCheckWritePropsAvailInAndOut = TRUE;
  1644. SAFEIRELEASE(pIEmbedObj2);
  1645. break;
  1646. }
  1647. if ( pbCheckFULLPropsAvailInAndOut != NULL)
  1648. {
  1649. *pbCheckFULLPropsAvailInAndOut = TRUE;
  1650. SAFEIRELEASE(pIEmbedObj2);
  1651. break;
  1652. }
  1653. _bstr_t bstrDesc;
  1654. hr = GetDescOfObject(pIEmbedObj2, bstrDesc,
  1655. rParsedInfo);
  1656. ONFAILTHROWERROR(hr);
  1657. PROPERTYDETAILS pdPropDet;
  1658. if (vtPropertyDerivation.vt == VT_BSTR)
  1659. pdPropDet.Derivation =
  1660. vtPropertyDerivation.bstrVal;
  1661. else
  1662. pdPropDet.Derivation = _bstr_t(TOKEN_NA);
  1663. if (bstrDesc != _bstr_t(""))
  1664. pdPropDet.Description = bstrDesc;
  1665. else
  1666. pdPropDet.Description = _bstr_t(TOKEN_NA);
  1667. hr = GetQualifiers(pIEmbedObj2, pdPropDet,
  1668. rParsedInfo);
  1669. if (!pdPropDet.Type)
  1670. pdPropDet.Type = _bstr_t(TOKEN_NA);
  1671. if (!pdPropDet.Operation)
  1672. pdPropDet.Operation = _bstr_t(TOKEN_NA);
  1673. // Add propertyname to property list in
  1674. // rParsedInfo
  1675. rParsedInfo.GetCmdSwitchesObject().
  1676. AddToPropDetMap(
  1677. vtPropertyName.bstrVal, pdPropDet);
  1678. VARIANTCLEAR(vtPropertyName);
  1679. VARIANTCLEAR(vtPropertyDerivation);
  1680. }
  1681. SAFEIRELEASE(pIEmbedObj2)
  1682. }
  1683. }
  1684. // Release memory held by vtProperties
  1685. VARIANTCLEAR(vtProperties);
  1686. // Free memory held by vtFormatName
  1687. VARIANTCLEAR(vtFormatName);
  1688. // Release pIEmbedObj
  1689. SAFEIRELEASE(pIEmbedObj);
  1690. break;
  1691. }
  1692. // Free memory held by vtFormatName
  1693. VARIANTCLEAR(vtFormatName);
  1694. // Release pIEmbedObj
  1695. SAFEIRELEASE(pIEmbedObj);
  1696. }
  1697. // Release memory held by vtFormats
  1698. VARIANTCLEAR(vtFormats);
  1699. }
  1700. SAFEIRELEASE(pIWbemObj);
  1701. }
  1702. catch(_com_error& e)
  1703. {
  1704. SAFEIRELEASE(pIWbemObj);
  1705. SAFEIRELEASE(pIEmbedObj);
  1706. SAFEIRELEASE(pIEmbedObj2);
  1707. VARIANTCLEAR(vtFormats);
  1708. VARIANTCLEAR(vtFormatName);
  1709. VARIANTCLEAR(vtProperties);
  1710. VARIANTCLEAR(vtPropertyName);
  1711. VARIANTCLEAR(vtPropertyDerivation);
  1712. hr = e.Error();
  1713. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  1714. }
  1715. catch(CHeap_Exception)
  1716. {
  1717. SAFEIRELEASE(pIWbemObj);
  1718. SAFEIRELEASE(pIEmbedObj);
  1719. SAFEIRELEASE(pIEmbedObj2);
  1720. VARIANTCLEAR(vtFormats);
  1721. VARIANTCLEAR(vtFormatName);
  1722. VARIANTCLEAR(vtProperties);
  1723. VARIANTCLEAR(vtPropertyName);
  1724. VARIANTCLEAR(vtPropertyDerivation);
  1725. hr = WBEM_E_OUT_OF_MEMORY;
  1726. _com_issue_error(hr);
  1727. }
  1728. return hr;
  1729. }
  1730. /*----------------------------------------------------------------------------
  1731. Name :GetDescOfObject
  1732. Synopsis :Get the Localized description from alias definition.
  1733. Type :Member Function
  1734. Input parameter(s):
  1735. pIWbemClassObject - IWbemLocator object
  1736. rParsedInfo - The parsed info from command line input.
  1737. Output parameter(s):
  1738. bstrDescription - Localized description
  1739. rParsedInfo` - The parsed info from command line input.
  1740. Return Type :HRESULT
  1741. Global Variables :None
  1742. Calling Syntax :GetDescOfObject(pIObject, bstrDescription,
  1743. rParsedInfo)
  1744. Notes :None
  1745. ----------------------------------------------------------------------------*/
  1746. HRESULT CCmdAlias::GetDescOfObject(IWbemClassObject* pIObject,
  1747. _bstr_t& bstrDescription,
  1748. CParsedInfo& rParsedInfo,
  1749. BOOL bLocalizeFlag)
  1750. {
  1751. HRESULT hr = S_OK;
  1752. DWORD dwThreadId = GetCurrentThreadId();
  1753. VARIANT vtDesc, vtRelPath;
  1754. VariantInit(&vtDesc);
  1755. VariantInit(&vtRelPath);
  1756. try
  1757. {
  1758. CHString chsMsg;
  1759. _bstr_t bstrRelPath;
  1760. _bstr_t bstrResult;
  1761. if (!bLocalizeFlag)
  1762. {
  1763. // Get "Description" property.
  1764. hr = pIObject->Get(_bstr_t(L"Description"), 0, &vtDesc, 0, 0);
  1765. if (m_bTrace || m_eloErrLogOpt)
  1766. {
  1767. chsMsg.Format(L"IWbemClassObject::Get(L\"Description\", 0,"
  1768. L"-, 0, 0)");
  1769. GetBstrTFromVariant(vtDesc, bstrResult);
  1770. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1771. dwThreadId, rParsedInfo, m_bTrace,
  1772. 0 ,bstrResult);
  1773. }
  1774. ONFAILTHROWERROR(hr);
  1775. if (vtDesc.vt == VT_BSTR )
  1776. bstrDescription = vtDesc.bstrVal;
  1777. VARIANTCLEAR(vtDesc);
  1778. }
  1779. else // Get the localized description
  1780. {
  1781. // Get the __RELPATH
  1782. hr = pIObject->Get(_bstr_t(L"__RELPATH"), 0, &vtRelPath, 0, 0);
  1783. if (m_bTrace || m_eloErrLogOpt)
  1784. {
  1785. chsMsg.Format(L"IWbemClassObject::Get(L\"__RELPATH\", 0,"
  1786. L"-, 0, 0)");
  1787. GetBstrTFromVariant(vtRelPath, bstrResult);
  1788. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1789. dwThreadId, rParsedInfo, m_bTrace,
  1790. 0, bstrResult);
  1791. }
  1792. ONFAILTHROWERROR(hr);
  1793. if ((vtRelPath.vt != VT_NULL) && (vtRelPath.vt != VT_EMPTY))
  1794. {
  1795. // Get localized description of the property.
  1796. hr = GetLocalizedDesc(vtRelPath.bstrVal,
  1797. bstrDescription, rParsedInfo);
  1798. if(FAILED(hr))
  1799. {
  1800. hr = S_OK;
  1801. WMIFormatMessage(IDS_E_NO_DESC, 0, bstrDescription, NULL);
  1802. }
  1803. }
  1804. VARIANTCLEAR(vtRelPath);
  1805. }
  1806. }
  1807. catch (_com_error& e)
  1808. {
  1809. VARIANTCLEAR(vtRelPath);
  1810. VARIANTCLEAR(vtDesc);
  1811. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  1812. hr = e.Error();
  1813. }
  1814. catch(CHeap_Exception)
  1815. {
  1816. VARIANTCLEAR(vtRelPath);
  1817. VARIANTCLEAR(vtDesc);
  1818. hr = WBEM_E_OUT_OF_MEMORY;
  1819. _com_issue_error(hr);
  1820. }
  1821. return hr;
  1822. }
  1823. /*----------------------------------------------------------------------------
  1824. Name :ObtainTranslateTableEntries
  1825. Synopsis :Obtain the translate table information from the alias
  1826. definition
  1827. Type :Member Function
  1828. Input parameter(s):
  1829. rParsedInfo - The parsed info from command line input.
  1830. Output parameter(s):
  1831. rParsedInfo - The parsed info from command line input.
  1832. Return Type :HRESULT
  1833. Global Variables :None
  1834. Calling Syntax :ObtainTranslateTableEntries(rParsedInfo)
  1835. Notes :None
  1836. ----------------------------------------------------------------------------*/
  1837. BOOL CCmdAlias::ObtainTranslateTableEntries(CParsedInfo& rParsedInfo)
  1838. {
  1839. BOOL bSuccess = TRUE;
  1840. HRESULT hr = S_OK;
  1841. IWbemClassObject *pIWbemObjOfTable = NULL,
  1842. *pIWbemObjOfTblEntry = NULL;
  1843. DWORD dwThreadId = GetCurrentThreadId();
  1844. VARIANT vtTblEntryArr, vtFromValue, vtToValue;
  1845. VariantInit(&vtTblEntryArr);
  1846. VariantInit(&vtFromValue);
  1847. VariantInit(&vtToValue);
  1848. try
  1849. {
  1850. CHString chsMsg;
  1851. _bstr_t bstrResult;
  1852. _bstr_t bstrPath = _bstr_t("MSFT_CliTranslateTable.Name='") +
  1853. _bstr_t(rParsedInfo.GetCmdSwitchesObject().GetTranslateTableName())+
  1854. _bstr_t(L"'");
  1855. hr = m_pIAliasNS->GetObject(bstrPath, 0, NULL,
  1856. &pIWbemObjOfTable, NULL);
  1857. if (m_bTrace || m_eloErrLogOpt)
  1858. {
  1859. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  1860. (WCHAR*) bstrPath);
  1861. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1862. dwThreadId, rParsedInfo, m_bTrace);
  1863. }
  1864. // do not add ONFAILTHROWERROR(hr) here, as following statement checks
  1865. // for validity
  1866. if ( pIWbemObjOfTable != NULL )
  1867. {
  1868. VariantInit(&vtTblEntryArr);
  1869. hr = pIWbemObjOfTable->Get(_bstr_t(L"Tbl"), 0,
  1870. &vtTblEntryArr, 0, 0 );
  1871. if ( vtTblEntryArr.vt != VT_NULL && vtTblEntryArr.vt != VT_EMPTY )
  1872. {
  1873. LONG lUpper = 0, lLower = 0;
  1874. hr = SafeArrayGetLBound(vtTblEntryArr.parray,
  1875. vtTblEntryArr.parray->cDims,
  1876. &lLower);
  1877. if ( m_eloErrLogOpt )
  1878. {
  1879. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  1880. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  1881. dwThreadId, rParsedInfo, FALSE);
  1882. }
  1883. ONFAILTHROWERROR(hr);
  1884. hr = SafeArrayGetUBound(vtTblEntryArr.parray,
  1885. vtTblEntryArr.parray->cDims,
  1886. &lUpper);
  1887. if ( m_eloErrLogOpt )
  1888. {
  1889. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  1890. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  1891. dwThreadId, rParsedInfo, FALSE);
  1892. }
  1893. ONFAILTHROWERROR(hr);
  1894. for (LONG lIndex = lLower; lIndex <= lUpper; lIndex++)
  1895. {
  1896. pIWbemObjOfTblEntry = NULL;
  1897. hr = SafeArrayGetElement(vtTblEntryArr.parray,&lIndex,
  1898. &pIWbemObjOfTblEntry);
  1899. if ( m_eloErrLogOpt )
  1900. {
  1901. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  1902. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  1903. dwThreadId, rParsedInfo, FALSE);
  1904. }
  1905. ONFAILTHROWERROR(hr);
  1906. VariantInit(&vtFromValue);
  1907. VariantInit(&vtToValue);
  1908. hr = pIWbemObjOfTblEntry->Get(_bstr_t(L"FromValue"), 0,
  1909. &vtFromValue, 0, 0 );
  1910. if (m_bTrace || m_eloErrLogOpt)
  1911. {
  1912. chsMsg.Format(L"IWbemClassObject::Get(L\"FromValue\","
  1913. L"0, -, 0, 0)");
  1914. GetBstrTFromVariant(vtFromValue, bstrResult);
  1915. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1916. (LPCWSTR)chsMsg, dwThreadId,
  1917. rParsedInfo, m_bTrace,
  1918. 0, bstrResult);
  1919. }
  1920. ONFAILTHROWERROR(hr);
  1921. hr = pIWbemObjOfTblEntry->Get(_bstr_t(L"ToValue"),
  1922. 0, &vtToValue, 0, 0 );
  1923. if (m_bTrace || m_eloErrLogOpt)
  1924. {
  1925. chsMsg.Format(L"IWbemClassObject::Get(L\"ToValue\", "
  1926. L"0, -, 0, 0)");
  1927. GetBstrTFromVariant(vtToValue, bstrResult);
  1928. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1929. (LPCWSTR)chsMsg, dwThreadId,
  1930. rParsedInfo, m_bTrace,
  1931. 0 , bstrResult);
  1932. }
  1933. ONFAILTHROWERROR(hr);
  1934. rParsedInfo.GetCmdSwitchesObject().
  1935. AddToAlsFrnNmsOrTrnsTblMap(
  1936. _bstr_t(vtFromValue.bstrVal),
  1937. _bstr_t(vtToValue.bstrVal) );
  1938. VARIANTCLEAR(vtFromValue);
  1939. VARIANTCLEAR(vtToValue);
  1940. SAFEIRELEASE(pIWbemObjOfTblEntry);
  1941. }
  1942. }
  1943. else
  1944. bSuccess = FALSE;
  1945. SAFEIRELEASE(pIWbemObjOfTable);
  1946. VARIANTCLEAR(vtTblEntryArr);
  1947. }
  1948. else
  1949. bSuccess = FALSE;
  1950. }
  1951. catch(_com_error& e)
  1952. {
  1953. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  1954. bSuccess = FALSE;
  1955. SAFEIRELEASE(pIWbemObjOfTable);
  1956. VARIANTCLEAR(vtTblEntryArr);
  1957. VARIANTCLEAR(vtFromValue);
  1958. VARIANTCLEAR(vtToValue);
  1959. SAFEIRELEASE(pIWbemObjOfTblEntry);
  1960. }
  1961. catch(CHeap_Exception)
  1962. {
  1963. bSuccess = FALSE;
  1964. SAFEIRELEASE(pIWbemObjOfTable);
  1965. VARIANTCLEAR(vtTblEntryArr);
  1966. VARIANTCLEAR(vtFromValue);
  1967. VARIANTCLEAR(vtToValue);
  1968. SAFEIRELEASE(pIWbemObjOfTblEntry);
  1969. hr = WBEM_E_OUT_OF_MEMORY;
  1970. _com_issue_error(hr);
  1971. }
  1972. return bSuccess;
  1973. }
  1974. /*----------------------------------------------------------------------------
  1975. Name :PopulateAliasFormatMap
  1976. Synopsis :populate the alias format map with the available formats
  1977. Type :Member Function
  1978. Input parameter(s):
  1979. rParsedInfo - reference to CParsedInfo class object
  1980. Output parameter(s):
  1981. rParsedInfo - reference to CParsedInfo class object
  1982. Return Type :HRESULT
  1983. Global Variables :None
  1984. Calling Syntax :PopulateAliasFormatMap(rParsedInfo)
  1985. Notes :None
  1986. ----------------------------------------------------------------------------*/
  1987. HRESULT CCmdAlias::PopulateAliasFormatMap(CParsedInfo& rParsedInfo)
  1988. {
  1989. // variables being used in this function.
  1990. HRESULT hr = S_OK;
  1991. IWbemClassObject *pIWbemObj = NULL;
  1992. IWbemClassObject *pIEmbedObj = NULL;
  1993. VARIANT vtFormats, vtFormatName;
  1994. // Initializing all Variants variables being used in this function.
  1995. VariantInit(&vtFormats);
  1996. VariantInit(&vtFormatName);
  1997. DWORD dwThreadId = GetCurrentThreadId();
  1998. try
  1999. {
  2000. CHString chsMsg;
  2001. _bstr_t bstrResult;
  2002. _bstr_t bstrPath = _bstr_t("MSFT_CliAlias.FriendlyName='") +
  2003. _bstr_t(rParsedInfo.GetCmdSwitchesObject().GetAliasName()) +
  2004. _bstr_t(L"'");
  2005. // Get alias object
  2006. hr = m_pIAliasNS->GetObject(bstrPath, 0, NULL, &pIWbemObj, NULL);
  2007. if (m_bTrace || m_eloErrLogOpt)
  2008. {
  2009. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  2010. (WCHAR*) bstrPath);
  2011. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2012. dwThreadId, rParsedInfo, m_bTrace);
  2013. }
  2014. ONFAILTHROWERROR(hr);
  2015. // Get Formats array property of alias object
  2016. hr = pIWbemObj->Get(_bstr_t(L"Formats"), 0, &vtFormats, 0, 0);
  2017. if (m_bTrace || m_eloErrLogOpt)
  2018. {
  2019. chsMsg.Format(L"IWbemClassObject::Get(L\"Formats\", 0,"
  2020. L"-, 0, 0)");
  2021. GetBstrTFromVariant(vtFormats, bstrResult);
  2022. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2023. dwThreadId, rParsedInfo, m_bTrace,
  2024. 0, bstrResult);
  2025. }
  2026. ONFAILTHROWERROR(hr);
  2027. if ( vtFormats.vt != VT_NULL && vtFormats.vt != VT_EMPTY )
  2028. {
  2029. // Get lower and upper bounds of Formats array
  2030. LONG lUpper = 0, lLower = 0;
  2031. hr = SafeArrayGetLBound(vtFormats.parray, vtFormats.parray->cDims,
  2032. &lLower);
  2033. if ( m_eloErrLogOpt )
  2034. {
  2035. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  2036. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2037. dwThreadId, rParsedInfo, FALSE);
  2038. }
  2039. ONFAILTHROWERROR(hr);
  2040. hr = SafeArrayGetUBound(vtFormats.parray, vtFormats.parray->cDims,
  2041. &lUpper);
  2042. if ( m_eloErrLogOpt )
  2043. {
  2044. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  2045. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2046. dwThreadId, rParsedInfo, FALSE);
  2047. }
  2048. ONFAILTHROWERROR(hr);
  2049. // Iterate through the Formats array property
  2050. for (LONG lIndex = lLower; lIndex <= lUpper; lIndex++)
  2051. {
  2052. VariantInit(&vtFormatName);
  2053. // Get this property.
  2054. hr =SafeArrayGetElement(vtFormats.parray,&lIndex,&pIEmbedObj);
  2055. if ( m_eloErrLogOpt )
  2056. {
  2057. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  2058. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  2059. dwThreadId, rParsedInfo, FALSE);
  2060. }
  2061. ONFAILTHROWERROR(hr);
  2062. hr = pIEmbedObj->Get(_bstr_t(L"Name"),0,&vtFormatName,0,0);
  2063. if (m_bTrace || m_eloErrLogOpt)
  2064. {
  2065. chsMsg.Format(L"IWbemClassObject::Get(L\"Name\", 0,"
  2066. L"-, 0, 0)");
  2067. GetBstrTFromVariant(vtFormatName, bstrResult);
  2068. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  2069. dwThreadId, rParsedInfo, m_bTrace,
  2070. 0, bstrResult);
  2071. }
  2072. ONFAILTHROWERROR(hr);
  2073. // To obtain properties from alias associated with the format
  2074. rParsedInfo.GetCmdSwitchesObject().SetListFormat(
  2075. _bstr_t(vtFormatName.bstrVal));
  2076. if ( ObtainAliasFormat(rParsedInfo) == TRUE )
  2077. {
  2078. CHARVECTOR cvProps = rParsedInfo.GetCmdSwitchesObject().
  2079. GetPropertyList();
  2080. CHARVECTOR::iterator cvIterator;
  2081. BSTRVECTOR bvProps;
  2082. for ( cvIterator = cvProps.begin();
  2083. cvIterator != cvProps.end();
  2084. cvIterator++ )
  2085. {
  2086. bvProps.push_back(_bstr_t(*cvIterator));
  2087. }
  2088. //Add format name to format list in rParsedInfo
  2089. rParsedInfo.GetCmdSwitchesObject().
  2090. AddToAliasFormatDetMap(vtFormatName.bstrVal, bvProps);
  2091. rParsedInfo.GetCmdSwitchesObject().ClearPropertyList();
  2092. }
  2093. SAFEIRELEASE(pIEmbedObj);
  2094. }
  2095. // Release memory held by vtFormats
  2096. VARIANTCLEAR(vtFormats);
  2097. }
  2098. // Release pIWbem object
  2099. SAFEIRELEASE(pIWbemObj);
  2100. }
  2101. catch(_com_error& e)
  2102. {
  2103. SAFEIRELEASE(pIEmbedObj);
  2104. SAFEIRELEASE(pIWbemObj);
  2105. VARIANTCLEAR(vtFormats);
  2106. VARIANTCLEAR(vtFormatName);
  2107. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  2108. hr = e.Error();
  2109. }
  2110. catch(CHeap_Exception)
  2111. {
  2112. SAFEIRELEASE(pIEmbedObj);
  2113. SAFEIRELEASE(pIWbemObj);
  2114. VARIANTCLEAR(vtFormats);
  2115. VARIANTCLEAR(vtFormatName);
  2116. hr = WBEM_E_OUT_OF_MEMORY;
  2117. _com_issue_error(hr);
  2118. }
  2119. return hr;
  2120. }
  2121. /*----------------------------------------------------------------------------
  2122. Name :ObtainTranslateTables
  2123. Synopsis :Obtain the information about translate tables available
  2124. Type :Member Function
  2125. Input parameter(s):
  2126. rParsedInfo - reference to CParsedInfo class object
  2127. Output parameter(s):
  2128. rParsedInfo - reference to CParsedInfo class object
  2129. Return Type :HRESULT
  2130. Global Variables :None
  2131. Calling Syntax :ObtainTranslateTables(rParsedInfo)
  2132. Notes :None
  2133. ----------------------------------------------------------------------------*/
  2134. HRESULT CCmdAlias::ObtainTranslateTables(CParsedInfo& rParsedInfo)
  2135. {
  2136. // variables being used in this function.
  2137. HRESULT hr = S_OK;
  2138. IEnumWbemClassObject *pIEnumObj = NULL;
  2139. IWbemClassObject *pIWbemObj = NULL;
  2140. DWORD dwThreadId = GetCurrentThreadId();
  2141. VARIANT vtName;
  2142. VariantInit(&vtName);
  2143. try
  2144. {
  2145. CHString chsMsg;
  2146. _bstr_t bstrResult;
  2147. // Get alias object
  2148. hr = m_pIAliasNS->ExecQuery(_bstr_t(L"WQL"),
  2149. _bstr_t(L"SELECT * FROM MSFT_CliTranslateTable"),
  2150. WBEM_FLAG_FORWARD_ONLY|
  2151. WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pIEnumObj);
  2152. if (m_bTrace || m_eloErrLogOpt)
  2153. {
  2154. chsMsg.Format(L"IWbemServices::ExecQuery(L\"WQL\","
  2155. L"L\"SELECT * FROM MSFT_CliTranslateTable\","
  2156. L"WBEM_FLAG_FORWARD_ONLY|WBEM_FLAG_RETURN_IMMEDIATELY,"
  2157. L"NULL, -)");
  2158. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2159. dwThreadId, rParsedInfo, m_bTrace);
  2160. }
  2161. ONFAILTHROWERROR(hr);
  2162. // Set the security
  2163. hr = SetSecurity(pIEnumObj, NULL, NULL, NULL, NULL,
  2164. rParsedInfo.GetGlblSwitchesObject().GetAuthenticationLevel(),
  2165. rParsedInfo.GetGlblSwitchesObject().GetImpersonationLevel());
  2166. if (m_bTrace || m_eloErrLogOpt)
  2167. {
  2168. chsMsg.Format(
  2169. L"CoSetProxyBlanket(-, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,"
  2170. L"NULL, %d, %d, -, EOAC_NONE)",
  2171. rParsedInfo.GetGlblSwitchesObject().GetAuthenticationLevel(),
  2172. rParsedInfo.GetGlblSwitchesObject().GetImpersonationLevel());
  2173. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2174. dwThreadId, rParsedInfo, m_bTrace);
  2175. }
  2176. ONFAILTHROWERROR(hr);
  2177. ULONG ulReturned = 0;
  2178. hr=pIEnumObj->Next(WBEM_INFINITE,1,&pIWbemObj,&ulReturned);
  2179. if (m_bTrace || m_eloErrLogOpt)
  2180. {
  2181. chsMsg.Format(L"IEnumWbemClassObject->Next"
  2182. L"(WBEM_INFINITE, 1, -, -)");
  2183. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2184. dwThreadId, rParsedInfo, m_bTrace);
  2185. }
  2186. ONFAILTHROWERROR(hr);
  2187. // Obtain the object starting at the current position in the
  2188. // enumeration and loop through the instance list.
  2189. while(ulReturned == 1)
  2190. {
  2191. VariantInit(&vtName);
  2192. // Gets "FriendlyName" array property of alias object
  2193. hr = pIWbemObj->Get(_bstr_t(L"Name"), 0, &vtName, 0, 0);
  2194. if (m_bTrace || m_eloErrLogOpt)
  2195. {
  2196. chsMsg.Format(L"IWbemClassObject::Get(L\"Name\", 0,"
  2197. L"-, 0, 0)");
  2198. GetBstrTFromVariant(vtName, bstrResult);
  2199. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2200. dwThreadId, rParsedInfo, m_bTrace,
  2201. 0, bstrResult);
  2202. }
  2203. ONFAILTHROWERROR(hr);
  2204. if (vtName.vt != VT_NULL && vtName.vt != VT_EMPTY)
  2205. {
  2206. rParsedInfo.GetCmdSwitchesObject().
  2207. AddToTrnsTablesList(vtName.bstrVal);
  2208. }
  2209. VARIANTCLEAR(vtName);
  2210. SAFEIRELEASE(pIWbemObj);
  2211. // Move to next instance in the enumeration.
  2212. hr = pIEnumObj->Next(WBEM_INFINITE, 1, &pIWbemObj, &ulReturned);
  2213. if (m_bTrace || m_eloErrLogOpt)
  2214. {
  2215. chsMsg.Format(
  2216. L"IEnumWbemClassObject->Next(WBEM_INFINITE, 1, -, -)");
  2217. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2218. dwThreadId, rParsedInfo, m_bTrace);
  2219. }
  2220. ONFAILTHROWERROR(hr);
  2221. }
  2222. SAFEIRELEASE(pIEnumObj);
  2223. }
  2224. catch(_com_error& e)
  2225. {
  2226. SAFEIRELEASE(pIEnumObj);
  2227. SAFEIRELEASE(pIWbemObj);
  2228. VARIANTCLEAR(vtName);
  2229. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  2230. hr = e.Error();
  2231. }
  2232. catch(CHeap_Exception)
  2233. {
  2234. SAFEIRELEASE(pIEnumObj);
  2235. SAFEIRELEASE(pIWbemObj);
  2236. VARIANTCLEAR(vtName);
  2237. hr = WBEM_E_OUT_OF_MEMORY;
  2238. _com_issue_error(hr);
  2239. }
  2240. return hr;
  2241. }
  2242. /*----------------------------------------------------------------------------
  2243. Name :ConnectToLocalizedNS
  2244. Synopsis :This function connects to localized WMI namespace
  2245. Type :Member Function
  2246. Input parameter(s):
  2247. rParsedInfo - reference to CParsedInfo class object.
  2248. pIWbemLocator- IWbemLocator object for connecting to WMI.
  2249. Output parameter(s):
  2250. rParsedInfo - reference to CParsedInfo class object.
  2251. Return Type :HRESULT
  2252. Global Variables :None
  2253. Calling Syntax :ConnectToLocalizedNS(rParsedInfo,pIWbemLocator)
  2254. Notes :None
  2255. ----------------------------------------------------------------------------*/
  2256. HRESULT CCmdAlias::ConnectToLocalizedNS(CParsedInfo& rParsedInfo,
  2257. IWbemLocator* pIWbemLocator)
  2258. {
  2259. DWORD dwThreadId = GetCurrentThreadId();
  2260. HRESULT hr = S_OK;
  2261. // If the /LOCALE value has been changed since last invocation
  2262. if (rParsedInfo.GetGlblSwitchesObject().GetLocaleFlag())
  2263. {
  2264. SAFEIRELEASE(m_pILocalizedNS);
  2265. try
  2266. {
  2267. CHString chsMsg;
  2268. _bstr_t bstrNS = _bstr_t(rParsedInfo.GetGlblSwitchesObject().
  2269. GetRole())
  2270. + _bstr_t(L"\\")
  2271. + _bstr_t(rParsedInfo.GetGlblSwitchesObject().
  2272. GetLocale());
  2273. // Connect to the specified namespace of Windows Management on the
  2274. // local computer using the locator object.
  2275. hr = Connect(pIWbemLocator, &m_pILocalizedNS,
  2276. bstrNS, NULL, NULL,
  2277. _bstr_t(rParsedInfo.GetGlblSwitchesObject().
  2278. GetLocale()), rParsedInfo);
  2279. // If /TRACE is ON
  2280. if (m_bTrace || m_eloErrLogOpt)
  2281. {
  2282. chsMsg.Format(
  2283. L"IWbemLocator::ConnectServer(L\"%s\", NULL, "
  2284. L"NULL, L\"%s\", 0L, NULL, NULL, -)",
  2285. (WCHAR*) bstrNS,
  2286. rParsedInfo.GetGlblSwitchesObject().GetLocale());
  2287. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2288. dwThreadId, rParsedInfo, m_bTrace);
  2289. }
  2290. ONFAILTHROWERROR(hr);
  2291. // If /TRACE is ON
  2292. if (m_bTrace || m_eloErrLogOpt)
  2293. {
  2294. chsMsg.Format(
  2295. L"CoSetProxyBlanket(-, RPC_C_AUTHN_WINNT, "
  2296. L"RPC_C_AUTHZ_NONE, NULL, %d, %d, -, EOAC_NONE)",
  2297. rParsedInfo.GetGlblSwitchesObject().GetAuthenticationLevel(),
  2298. rParsedInfo.GetGlblSwitchesObject().GetImpersonationLevel());
  2299. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2300. dwThreadId, rParsedInfo, m_bTrace);
  2301. }
  2302. ONFAILTHROWERROR(hr);
  2303. rParsedInfo.GetGlblSwitchesObject().SetLocaleFlag(FALSE);
  2304. }
  2305. catch(_com_error& e)
  2306. {
  2307. // Set the COM error
  2308. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  2309. hr = e.Error();
  2310. }
  2311. catch(CHeap_Exception)
  2312. {
  2313. // Set the COM error
  2314. hr = WBEM_E_OUT_OF_MEMORY;
  2315. _com_issue_error(hr);
  2316. }
  2317. }
  2318. return hr;
  2319. }
  2320. /*----------------------------------------------------------------------------
  2321. Name :GetLocalizedDesc
  2322. Synopsis :This function retrieves the localized description for
  2323. the object with given relative path,
  2324. Type :Member Function
  2325. Input parameter(s):
  2326. bstrRelPath - relativepath of the object for which
  2327. localized description has to be retrieved.
  2328. rParsedInfo - reference to CParsedInfo class object.
  2329. Output parameter(s):
  2330. bstrDesc - localized description
  2331. rParsedInfo - reference to CParsedInfo class object.
  2332. Return Type :HRESULT
  2333. Global Variables :None
  2334. Calling Syntax :GetLocalizedDesc(bstrRelPath, bstrDesc, rParsedInfo)
  2335. Notes :None
  2336. ----------------------------------------------------------------------------*/
  2337. HRESULT CCmdAlias::GetLocalizedDesc(_bstr_t bstrRelPath,
  2338. _bstr_t& bstrDesc,
  2339. CParsedInfo& rParsedInfo)
  2340. {
  2341. HRESULT hr = S_OK;
  2342. IWbemClassObject *pIObject = NULL;
  2343. DWORD dwThreadId = GetCurrentThreadId();
  2344. VARIANT vtDesc, vtTemp;
  2345. VariantInit(&vtDesc);
  2346. VariantInit(&vtTemp);
  2347. try
  2348. {
  2349. CHString chsMsg;
  2350. _bstr_t bstrResult;
  2351. CHString sTemp((WCHAR*)bstrRelPath);
  2352. // Substitue escape characters i.e. replace '\"' with '\\\"'
  2353. SubstituteEscapeChars(sTemp, L"\"");
  2354. // Object path
  2355. _bstr_t bstrPath =
  2356. _bstr_t(L"MSFT_LocalizablePropertyValue.ObjectLocator=\"\",PropertyName=")
  2357. + _bstr_t(L"\"Description\",RelPath=\"")
  2358. + _bstr_t(sTemp) + _bstr_t(L"\"");
  2359. // Retrieve the object
  2360. hr = m_pILocalizedNS->GetObject(bstrPath, 0, NULL, &pIObject, NULL);
  2361. if (m_bTrace || m_eloErrLogOpt)
  2362. {
  2363. chsMsg.Format(
  2364. L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  2365. (WCHAR*) bstrPath);
  2366. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2367. dwThreadId, rParsedInfo, m_bTrace);
  2368. }
  2369. ONFAILTHROWERROR(hr);
  2370. // Get localized description of the property.
  2371. hr = pIObject->Get(_bstr_t(L"Text"), 0, &vtDesc, 0, 0);
  2372. if (m_bTrace || m_eloErrLogOpt)
  2373. {
  2374. chsMsg.Format(L"IWbemClassObject::Get(L\"Text\", 0, -, 0, 0)");
  2375. GetBstrTFromVariant(vtDesc, bstrResult);
  2376. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2377. dwThreadId, rParsedInfo, m_bTrace,
  2378. 0, bstrResult);
  2379. }
  2380. ONFAILTHROWERROR(hr);
  2381. if (vtDesc.vt != VT_EMPTY && vtDesc.vt != VT_NULL)
  2382. {
  2383. // Get lower and upper bounds of 'Text' array
  2384. LONG lUpper = 0, lLower = 0;
  2385. hr = SafeArrayGetLBound(vtDesc.parray, vtDesc.parray->cDims,
  2386. &lLower);
  2387. ONFAILTHROWERROR(hr);
  2388. hr = SafeArrayGetUBound(vtDesc.parray, vtDesc.parray->cDims,
  2389. &lUpper);
  2390. ONFAILTHROWERROR(hr);
  2391. // Iterate through the Formats array property
  2392. for (LONG lIndex = lLower; lIndex <= lUpper; lIndex++)
  2393. {
  2394. BSTR bstrTemp = NULL;
  2395. hr = SafeArrayGetElement(vtDesc.parray, &lIndex, &bstrTemp);
  2396. ONFAILTHROWERROR(hr);
  2397. if (bstrTemp)
  2398. bstrDesc += bstrTemp;
  2399. }
  2400. }
  2401. VariantClear(&vtDesc);
  2402. SAFEIRELEASE(pIObject);
  2403. }
  2404. catch (_com_error& e)
  2405. {
  2406. VariantClear(&vtTemp);
  2407. VariantClear(&vtDesc);
  2408. SAFEIRELEASE(pIObject);
  2409. hr = e.Error();
  2410. }
  2411. catch(CHeap_Exception)
  2412. {
  2413. VariantClear(&vtTemp);
  2414. VariantClear(&vtDesc);
  2415. SAFEIRELEASE(pIObject);
  2416. hr = WBEM_E_OUT_OF_MEMORY;
  2417. _com_issue_error(hr);
  2418. }
  2419. return hr;
  2420. }
  2421. /*----------------------------------------------------------------------------
  2422. Name :GetQualifiers
  2423. Synopsis :This function retrieves the qualifiers associated with
  2424. propety/parameter referred by pIWbemClassObject
  2425. Type :Member Function
  2426. Input parameter(s):
  2427. pIWbemClassObject - pointer to IWbemClassObject
  2428. rPropDet - reference to PROPERTYDETAILS object
  2429. rParsedInfo - reference to CParsedInfo class object.
  2430. Output parameter(s):
  2431. rPropDet - reference to PROPERTYDETAILS object
  2432. rParsedInfo - reference to CParsedInfo class object.
  2433. Return Type :HRESULT
  2434. Global Variables :None
  2435. Calling Syntax :GetQualifiers(pIObj, rPropDet, rParsedInfo)
  2436. Notes :None
  2437. ----------------------------------------------------------------------------*/
  2438. HRESULT CCmdAlias::GetQualifiers(IWbemClassObject *pIWbemClassObject,
  2439. PROPERTYDETAILS& rPropDet,
  2440. CParsedInfo& rParsedInfo)
  2441. {
  2442. IWbemClassObject *pIWbemQualObject = NULL;
  2443. HRESULT hr = S_OK;
  2444. DWORD dwThreadId = GetCurrentThreadId();
  2445. VARIANT vtQualifiers, vtQualName, vtQualValues;
  2446. VariantInit(&vtQualifiers);
  2447. VariantInit(&vtQualName);
  2448. VariantInit(&vtQualValues);
  2449. try
  2450. {
  2451. CHString chsMsg;
  2452. _bstr_t bstrResult;
  2453. //Getting the "Qualifiers" property.
  2454. hr=pIWbemClassObject->Get(_bstr_t(L"Qualifiers"), 0,
  2455. &vtQualifiers, 0, 0);
  2456. if (m_bTrace || m_eloErrLogOpt)
  2457. {
  2458. chsMsg.Format(L"IWbemClassObject::Get"
  2459. L"(L\"Qualifiers\", 0, -, 0, 0)");
  2460. GetBstrTFromVariant(vtQualifiers, bstrResult);
  2461. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  2462. (LPCWSTR)chsMsg, dwThreadId,
  2463. rParsedInfo, m_bTrace, 0, bstrResult);
  2464. }
  2465. ONFAILTHROWERROR(hr);
  2466. if ( vtQualifiers.vt != VT_NULL && vtQualifiers.vt != VT_EMPTY )
  2467. {
  2468. LONG lLower = 0, lUpper = 0;
  2469. hr = SafeArrayGetLBound(vtQualifiers.parray,
  2470. vtQualifiers.parray->cDims, &lLower);
  2471. if ( m_eloErrLogOpt )
  2472. {
  2473. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  2474. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2475. dwThreadId, rParsedInfo, FALSE);
  2476. }
  2477. ONFAILTHROWERROR(hr);
  2478. hr = SafeArrayGetUBound(vtQualifiers.parray,
  2479. vtQualifiers.parray->cDims, &lUpper);
  2480. if ( m_eloErrLogOpt )
  2481. {
  2482. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  2483. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2484. dwThreadId, rParsedInfo, FALSE);
  2485. }
  2486. ONFAILTHROWERROR(hr);
  2487. // Iterate through the Properties array property
  2488. for(LONG lIndex=lLower; lIndex<=lUpper; lIndex++)
  2489. {
  2490. pIWbemQualObject = NULL;
  2491. // Get this property.
  2492. hr = SafeArrayGetElement(vtQualifiers.parray,
  2493. &lIndex, &pIWbemQualObject);
  2494. if ( m_eloErrLogOpt )
  2495. {
  2496. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  2497. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  2498. dwThreadId, rParsedInfo, FALSE);
  2499. }
  2500. ONFAILTHROWERROR(hr);
  2501. //Getting the "Name" property
  2502. hr = pIWbemQualObject->Get(_bstr_t(L"Name"), 0,
  2503. &vtQualName,0,0);
  2504. if (m_bTrace || m_eloErrLogOpt)
  2505. {
  2506. chsMsg.Format(L"IWbemClassObject::Get"
  2507. L"(L\"Name\", 0, -, 0, 0)");
  2508. GetBstrTFromVariant(vtQualName, bstrResult);
  2509. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  2510. dwThreadId, rParsedInfo, m_bTrace,
  2511. 0, bstrResult);
  2512. }
  2513. ONFAILTHROWERROR(hr);
  2514. //Getting the "QualifierValue" property.
  2515. hr=pIWbemQualObject->Get(_bstr_t(L"QualifierValue"),0,
  2516. &vtQualValues, 0, 0);
  2517. if (m_bTrace || m_eloErrLogOpt)
  2518. {
  2519. chsMsg.Format(L"IWbemClassObject::Get"
  2520. L"(L\"QualifierValue\", 0, -, 0, 0)");
  2521. GetBstrTFromVariant(vtQualValues, bstrResult);
  2522. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  2523. dwThreadId, rParsedInfo, m_bTrace,
  2524. 0, bstrResult);
  2525. }
  2526. ONFAILTHROWERROR(hr);
  2527. BSTRVECTOR bvQualValues;
  2528. if ( vtQualValues.vt != VT_NULL &&
  2529. vtQualValues.vt != VT_EMPTY )
  2530. {
  2531. LONG lILower = 0, lIUpper = 0;
  2532. hr = SafeArrayGetLBound(vtQualValues.parray,
  2533. vtQualValues.parray->cDims, &lILower);
  2534. if ( m_eloErrLogOpt )
  2535. {
  2536. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  2537. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  2538. dwThreadId, rParsedInfo, FALSE);
  2539. }
  2540. ONFAILTHROWERROR(hr);
  2541. hr = SafeArrayGetUBound(vtQualValues.parray,
  2542. vtQualValues.parray->cDims, &lIUpper);
  2543. if ( m_eloErrLogOpt )
  2544. {
  2545. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  2546. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  2547. (LPCWSTR)chsMsg, dwThreadId,
  2548. rParsedInfo, FALSE);
  2549. }
  2550. ONFAILTHROWERROR(hr);
  2551. BOOL bIsType = FALSE;
  2552. BOOL bIsRead = FALSE;
  2553. BOOL bIsWrite = FALSE;
  2554. BOOL bIsIn = FALSE;
  2555. BOOL bIsOut = FALSE;
  2556. if (CompareTokens((WCHAR*)vtQualName.bstrVal,
  2557. _T("CIMTYPE")))
  2558. {
  2559. bIsType = TRUE;
  2560. }
  2561. else if (CompareTokens((WCHAR*)vtQualName.bstrVal,
  2562. _T("read")))
  2563. {
  2564. bIsRead = TRUE;
  2565. }
  2566. else if (CompareTokens((WCHAR*)vtQualName.bstrVal,
  2567. _T("write")))
  2568. {
  2569. bIsWrite = TRUE;
  2570. }
  2571. else if (CompareTokens((WCHAR*)vtQualName.bstrVal,
  2572. _T("In")))
  2573. {
  2574. bIsIn = TRUE;
  2575. }
  2576. else if (CompareTokens((WCHAR*)vtQualName.bstrVal,
  2577. _T("Out")))
  2578. {
  2579. bIsOut = TRUE;
  2580. }
  2581. // Iterate through the Properties array property
  2582. for(LONG lIIndex=lILower; lIIndex<=lIUpper; lIIndex++)
  2583. {
  2584. BSTR bstrQualValue = NULL;
  2585. // Get this property.
  2586. hr = SafeArrayGetElement(vtQualValues.parray,
  2587. &lIIndex, &bstrQualValue);
  2588. if ( m_eloErrLogOpt )
  2589. {
  2590. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  2591. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  2592. (LPCWSTR)chsMsg, dwThreadId,
  2593. rParsedInfo, FALSE);
  2594. }
  2595. ONFAILTHROWERROR(hr);
  2596. if (bstrQualValue)
  2597. bvQualValues.push_back(bstrQualValue);
  2598. if ( lIIndex == 0 )
  2599. {
  2600. if ( bIsType == TRUE )
  2601. {
  2602. rPropDet.Type = bstrQualValue;
  2603. }
  2604. else if ( bIsRead == TRUE &&
  2605. CompareTokens((WCHAR*)bstrQualValue, _T("true")))
  2606. {
  2607. if (!rPropDet.Operation)
  2608. rPropDet.Operation += _bstr_t("Read");
  2609. else
  2610. rPropDet.Operation += _bstr_t("/Read");
  2611. }
  2612. else if ( bIsWrite == TRUE &&
  2613. CompareTokens((WCHAR*)bstrQualValue, _T("true")))
  2614. {
  2615. if (!rPropDet.Operation)
  2616. rPropDet.Operation += _bstr_t("Write");
  2617. else
  2618. rPropDet.Operation += _bstr_t("/Write");
  2619. }
  2620. else if ( bIsIn == TRUE &&
  2621. CompareTokens((WCHAR*)bstrQualValue, _T("true")))
  2622. {
  2623. rPropDet.InOrOut = INP;
  2624. }
  2625. else if ( bIsOut == TRUE &&
  2626. CompareTokens((WCHAR*)bstrQualValue, _T("true")))
  2627. {
  2628. rPropDet.InOrOut = OUTP;
  2629. }
  2630. }
  2631. }
  2632. VARIANTCLEAR(vtQualValues);
  2633. }
  2634. rPropDet.QualDetMap.insert
  2635. (QUALDETMAP::value_type(vtQualName.bstrVal, bvQualValues));
  2636. VARIANTCLEAR(vtQualName);
  2637. SAFEIRELEASE(pIWbemQualObject);
  2638. }
  2639. VARIANTCLEAR(vtQualifiers);
  2640. }
  2641. }
  2642. catch (_com_error& e)
  2643. {
  2644. VARIANTCLEAR(vtQualValues);
  2645. VARIANTCLEAR(vtQualName);
  2646. VARIANTCLEAR(vtQualifiers);
  2647. SAFEIRELEASE(pIWbemQualObject);
  2648. hr = e.Error();
  2649. // Set the COM error
  2650. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  2651. }
  2652. catch(CHeap_Exception)
  2653. {
  2654. VARIANTCLEAR(vtQualValues);
  2655. VARIANTCLEAR(vtQualName);
  2656. VARIANTCLEAR(vtQualifiers);
  2657. SAFEIRELEASE(pIWbemQualObject);
  2658. hr = WBEM_E_OUT_OF_MEMORY;
  2659. _com_issue_error(hr);
  2660. }
  2661. return hr;
  2662. }
  2663. /*----------------------------------------------------------------------------
  2664. Name :AreMethodsAvailable
  2665. Synopsis :Checks whether method are available with alias or not.
  2666. Type :Member Function
  2667. Input parameter(s):
  2668. rParsedInfo - reference to CParsedInfo class object.
  2669. Output parameter(s):None
  2670. Return Type :BOOL
  2671. Global Variables :None
  2672. Calling Syntax :AreMethodsAvailable(rParsedInfo)
  2673. Notes :None
  2674. ----------------------------------------------------------------------------*/
  2675. BOOL CCmdAlias::AreMethodsAvailable(CParsedInfo& rParsedInfo)
  2676. {
  2677. BOOL bMethAvail = TRUE;
  2678. HRESULT hr = S_OK;
  2679. IWbemClassObject *pIWbemObj = NULL;
  2680. DWORD dwThreadId = GetCurrentThreadId();
  2681. VARIANT vtVerbs;
  2682. VariantInit(&vtVerbs);
  2683. try
  2684. {
  2685. CHString chsMsg;
  2686. _bstr_t bstrResult;
  2687. _bstr_t bstrPath = _bstr_t("MSFT_CliAlias.FriendlyName='") +
  2688. _bstr_t(rParsedInfo.GetCmdSwitchesObject().GetAliasName())+
  2689. _bstr_t(L"'");
  2690. //Retrieving the object from the namespace in m_pIAliasNS
  2691. hr = m_pIAliasNS->GetObject(bstrPath, 0, NULL, &pIWbemObj, NULL);
  2692. if (m_bTrace || m_eloErrLogOpt)
  2693. {
  2694. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  2695. (WCHAR*) bstrPath);
  2696. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2697. dwThreadId, rParsedInfo, m_bTrace);
  2698. }
  2699. ONFAILTHROWERROR(hr);
  2700. // Get "Verbs" property.
  2701. hr = pIWbemObj->Get(_bstr_t(L"Verbs"), 0, &vtVerbs, 0, 0) ;
  2702. if (m_bTrace || m_eloErrLogOpt)
  2703. {
  2704. chsMsg.Format(L"IWbemClassObject::Get(L\"Verbs\", 0, -, 0, 0)");
  2705. GetBstrTFromVariant(vtVerbs, bstrResult);
  2706. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2707. dwThreadId, rParsedInfo, m_bTrace,
  2708. 0, bstrResult);
  2709. }
  2710. ONFAILTHROWERROR(hr);
  2711. if ( vtVerbs.vt == VT_NULL || vtVerbs.vt == VT_EMPTY )
  2712. bMethAvail = FALSE;
  2713. SAFEIRELEASE(pIWbemObj);
  2714. VARIANTCLEAR(vtVerbs);
  2715. }
  2716. catch(_com_error& e)
  2717. {
  2718. bMethAvail = FALSE;
  2719. SAFEIRELEASE(pIWbemObj);
  2720. VARIANTCLEAR(vtVerbs);
  2721. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  2722. bMethAvail = FALSE;
  2723. }
  2724. catch(CHeap_Exception)
  2725. {
  2726. bMethAvail = FALSE;
  2727. SAFEIRELEASE(pIWbemObj);
  2728. VARIANTCLEAR(vtVerbs);
  2729. bMethAvail = FALSE;
  2730. hr = WBEM_E_OUT_OF_MEMORY;
  2731. _com_issue_error(hr);
  2732. }
  2733. return bMethAvail;
  2734. }