Leaked source code of windows server 2003
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.

91 lines
1.9 KiB

  1. #include "precomp.h"
  2. #include <stdio.h>
  3. #include <wbemcli.h>
  4. #include "txttempl.h"
  5. #include "comutl.h"
  6. extern "C" int __cdecl wmain( int argc, wchar_t* argv[] )
  7. {
  8. if ( argc < 3 )
  9. {
  10. printf("Usage:: tmpltest <objref> <tmplstr>\n");
  11. return 1;
  12. }
  13. LPWSTR wszPath = argv[1];
  14. LPWSTR wszTmpl = argv[2];
  15. HRESULT hr;
  16. CoInitialize( NULL );
  17. {
  18. CWbemPtr<IWbemLocator> pLocator;
  19. CWbemPtr<IWbemServices> pSvc;
  20. hr = CoCreateInstance( CLSID_WbemLocator,
  21. NULL,
  22. CLSCTX_SERVER,
  23. IID_IWbemLocator,
  24. (void**)&pLocator );
  25. if ( FAILED(hr) )
  26. {
  27. printf("ERROR CoCIing WbemLocator : hr = 0x%x\n",hr);
  28. return 1;
  29. }
  30. hr = pLocator->ConnectServer( L"root",
  31. NULL,
  32. NULL,
  33. NULL,
  34. 0,
  35. NULL,
  36. NULL,
  37. &pSvc );
  38. if ( FAILED(hr) )
  39. {
  40. wprintf( L"ERROR Connecting to WMI : hr = 0x%x\n", hr );
  41. return 1;
  42. }
  43. CWbemPtr<IWbemClassObject> pObj;
  44. hr = pSvc->GetObject( wszPath, 0, NULL, &pObj, NULL );
  45. if ( FAILED(hr) )
  46. {
  47. printf("ERROR Fetching Obj : hr = 0x%x\n", hr );
  48. return 1;
  49. }
  50. CTextTemplate TextTmpl( wszTmpl );
  51. BSTR bstrNewQuery = TextTmpl.Apply( pObj );
  52. if ( bstrNewQuery == NULL )
  53. {
  54. printf("Failed getting applying template str to obj\n" );
  55. return 1;
  56. }
  57. wprintf( L"Template string is %s\n", bstrNewQuery );
  58. SysFreeString( bstrNewQuery );
  59. }
  60. CoUninitialize();
  61. return 0;
  62. }