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.

162 lines
3.5 KiB

  1. #ifndef INITGUID
  2. #define INITGUID
  3. #endif
  4. #ifndef WIN32_LEAN_AND_MEAN
  5. #define WIN32_LEAN_AND_MEAN
  6. #endif
  7. #ifndef _WIN32_WINNT
  8. #define _WIN32_WINNT 0x0500
  9. #endif
  10. #include <windows.h>
  11. #include <tchar.h>
  12. #include <iwamreg.h> // MD_ & IIS_MD_ defines
  13. #include "apppool.h"
  14. #include "common.h"
  15. //--------------------------------------------------------------------------
  16. HRESULT CUDDIAppPool::Init( void )
  17. {
  18. ENTER();
  19. HRESULT hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
  20. if( FAILED( hr ) )
  21. {
  22. LogError( TEXT( "RecycleApplicationPool(): CoInitializeEx() failed" ), HRESULT_CODE( hr ) );
  23. return hr;
  24. }
  25. hr = CoCreateInstance(
  26. CLSID_WamAdmin,
  27. NULL,
  28. CLSCTX_ALL,
  29. IID_IWamAdmin,
  30. (void**)&pIWamAdmin );
  31. if( FAILED( hr ) )
  32. {
  33. LogError( TEXT( "RecycleApplicationPool(): CoCreateInstance() failed" ), HRESULT_CODE(hr) );
  34. return hr;
  35. }
  36. hr = pIWamAdmin->QueryInterface( IID_IIISApplicationAdmin, (void **) &pIIISApplicationAdmin );
  37. if( FAILED( hr ) )
  38. {
  39. LogError( TEXT( "RecycleApplicationPool(): QueryInterface() failed" ), HRESULT_CODE(hr) );
  40. return hr;
  41. }
  42. return ERROR_SUCCESS;
  43. }
  44. //--------------------------------------------------------------------------
  45. CUDDIAppPool::~CUDDIAppPool( void )
  46. {
  47. ENTER();
  48. if( pIIISApplicationAdmin )
  49. pIIISApplicationAdmin->Release();
  50. CoUninitialize();
  51. }
  52. //--------------------------------------------------------------------------
  53. // recycle the UDDI app pool
  54. HRESULT CUDDIAppPool::Recycle( void )
  55. {
  56. ENTER();
  57. HRESULT hr = Init();
  58. if( FAILED( hr ) )
  59. {
  60. Log( TEXT( "Error recycling the UDDI application pool = %d" ), HRESULT_CODE( hr ) );
  61. return hr;
  62. }
  63. hr = pIIISApplicationAdmin->RecycleApplicationPool( APPPOOLNAME );
  64. if( HRESULT_CODE(hr) == ERROR_OBJECT_NOT_FOUND )
  65. {
  66. //
  67. // the RecycleApplicationPool() method returns an Object Not Found error if you try to
  68. // recycle the app pool when the app pool is not running
  69. //
  70. Log( TEXT( "The Application Pool %s is NOT running - unable to recycle this pool" ), APPPOOLNAME );
  71. }
  72. else if( FAILED( hr ) )
  73. {
  74. Log( TEXT( "Error recycling the UDDI application pool = %d" ), HRESULT_CODE( hr ) );
  75. }
  76. return hr;
  77. }
  78. //--------------------------------------------------------------------------
  79. // delete an app pool
  80. HRESULT CUDDIAppPool::Delete( void )
  81. {
  82. ENTER();
  83. //
  84. // init the com interface to the IIS metabase
  85. //
  86. HRESULT hr = Init();
  87. if( FAILED( hr ) )
  88. {
  89. Log( TEXT( "Error stopping UDDI application pool = %d" ), HRESULT_CODE( hr ) );
  90. return hr;
  91. }
  92. //
  93. // enumerate all the applications in the app pool and delete them
  94. //
  95. BSTR bstrBuffer;
  96. while( ERROR_SUCCESS == pIIISApplicationAdmin->EnumerateApplicationsInPool( APPPOOLNAME, &bstrBuffer ) )
  97. {
  98. //
  99. // returns an empty string when done
  100. //
  101. if( 0 == _tcslen( bstrBuffer ) )
  102. break;
  103. //
  104. // unload the application
  105. //
  106. if ( pIWamAdmin )
  107. {
  108. pIWamAdmin->AppUnLoad( bstrBuffer, true );
  109. }
  110. //
  111. // delete this application
  112. //
  113. hr = pIIISApplicationAdmin->DeleteApplication( bstrBuffer, true );
  114. SysFreeString( bstrBuffer );
  115. if( FAILED( hr ) )
  116. {
  117. Log( TEXT( "Error deleting UDDI application from the app pool, error = %d" ), HRESULT_CODE( hr ) );
  118. return hr;
  119. }
  120. }
  121. //
  122. // delete the application pool
  123. //
  124. hr = pIIISApplicationAdmin->DeleteApplicationPool( APPPOOLNAME );
  125. if( FAILED( hr ) )
  126. {
  127. Log( TEXT( "Error deleting the UDDI application pool = %d" ), HRESULT_CODE( hr ) );
  128. return hr;
  129. }
  130. return ERROR_SUCCESS;
  131. }