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.

92 lines
1.9 KiB

  1. #ifndef _WIN32_WINNT
  2. #define _WIN32_WINNT 0x0500
  3. #endif
  4. #ifndef INITGUID
  5. #define INITGUID // must be before iadmw.h
  6. #endif
  7. #include <stdio.h>
  8. #include <objbase.h>
  9. #include <iadmw.h> // Interface header
  10. #include <iiscnfg.h> // MD_ & IIS_MD_ defines
  11. #include "appcompat.h"
  12. #define REASONABLE_TIMEOUT 1000
  13. HRESULT IsIIS5CompatMode( bool *pbIsIIS5CompatMode )
  14. {
  15. IMSAdminBase* pIMSAdminBase = NULL;
  16. METADATA_HANDLE hMetabase = NULL;
  17. HRESULT hr = 0;
  18. *pbIsIIS5CompatMode = false;
  19. hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
  20. if( FAILED( hr ) )
  21. {
  22. return hr;
  23. }
  24. __try
  25. {
  26. hr = CoCreateInstance(
  27. CLSID_MSAdminBase,
  28. NULL,
  29. CLSCTX_ALL,
  30. IID_IMSAdminBase,
  31. (void**)&pIMSAdminBase );
  32. if( FAILED( hr ) )
  33. {
  34. // this occurs with a 1058 ERROR_SERVICE_DISABLED if the service is disabled
  35. __leave;
  36. }
  37. METADATA_RECORD mr = {0};
  38. //
  39. // open the key and get a handle
  40. //
  41. hr = pIMSAdminBase->OpenKey( METADATA_MASTER_ROOT_HANDLE,
  42. TEXT( "/LM/W3SVC" ),
  43. METADATA_PERMISSION_READ,
  44. REASONABLE_TIMEOUT,
  45. &hMetabase );
  46. if( FAILED( hr ) )
  47. {
  48. __leave;
  49. }
  50. DWORD dwIISIsolationModeEnabled = 0;
  51. mr.dwMDIdentifier = 9203; // iis5isolationmode=9203
  52. mr.dwMDAttributes = 0;
  53. mr.dwMDUserType = IIS_MD_UT_SERVER;
  54. mr.dwMDDataType = DWORD_METADATA;
  55. mr.dwMDDataLen = sizeof( DWORD );
  56. mr.pbMDData = reinterpret_cast<unsigned char *> ( &dwIISIsolationModeEnabled );
  57. //
  58. // See if MD_APPPOOL_FRIENDLY_NAME exists
  59. //
  60. DWORD dwMDRequiredDataLen = 0;
  61. hr = pIMSAdminBase->GetData( hMetabase, /* subkey= */ TEXT(""), &mr, &dwMDRequiredDataLen );
  62. if( FAILED( hr ) )
  63. {
  64. __leave;
  65. }
  66. *pbIsIIS5CompatMode = ( dwIISIsolationModeEnabled > 0 );
  67. }
  68. __finally
  69. {
  70. if( pIMSAdminBase && hMetabase )
  71. pIMSAdminBase->CloseKey( hMetabase );
  72. CoUninitialize();
  73. }
  74. return hr;
  75. }