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.

208 lines
5.9 KiB

  1. // a small object to query and control the state of the w3 server
  2. // created 4/14/97 BoydM
  3. #include "stdafx.h"
  4. #include "resource.h"
  5. #include "ServCntr.h"
  6. #include "mbobjs.h"
  7. #include "pwsctrl.h"
  8. #include <isvctrl.h>
  9. #define SERVER_WINDOWCLASS_NAME INET_SERVER_WINDOW_CLASS
  10. #define REGKEY_STP _T("SOFTWARE\\Microsoft\\INetStp")
  11. #define REGKEY_INSTALLKEY _T("InstallPath")
  12. extern BOOL g_fShutdownMode;
  13. //------------------------------------------------------------------------
  14. CW3ServerControl::CW3ServerControl()
  15. {
  16. OSVERSIONINFO info_os;
  17. info_os.dwOSVersionInfoSize = sizeof(info_os);
  18. // record what sort of operating system we are running on
  19. m_fIsWinNT = FALSE;
  20. if ( GetVersionEx( &info_os ) )
  21. {
  22. if ( info_os.dwPlatformId == VER_PLATFORM_WIN32_NT )
  23. m_fIsWinNT = TRUE;
  24. }
  25. }
  26. //------------------------------------------------------------------------
  27. int CW3ServerControl::GetServerState()
  28. {
  29. CWrapMetaBase mb;
  30. DWORD dw;
  31. // if the service is totally shut down, return stopped
  32. if ( g_fShutdownMode )
  33. return MD_SERVER_STATE_STOPPED;
  34. // see if inetinfo is running - win95 only
  35. if ( !m_fIsWinNT && !IsInetinfoRunning() )
  36. return MD_SERVER_STATE_STOPPED;
  37. // init the mb object. If it fails then the server app is probably not running
  38. if ( !mb.FInit() )
  39. {
  40. return MD_SERVER_STATE_STOPPED;
  41. }
  42. // open the metabase so we can get the current state
  43. if ( !mb.Open(MB_SERVER_KEY_UPDATE) )
  44. {
  45. return MD_SERVER_STATE_STOPPED;
  46. }
  47. // get the server status flag
  48. if ( !mb.GetDword( _T(""), MD_SERVER_STATE, IIS_MD_UT_SERVER, &dw ) )
  49. {
  50. DWORD err = GetLastError( );
  51. if ( err == RPC_E_SERVERCALL_RETRYLATER )
  52. {
  53. mb.Close();
  54. return STATE_TRY_AGAIN;
  55. }
  56. }
  57. // close the metabase object
  58. mb.Close();
  59. // return the obtained state
  60. return dw;
  61. }
  62. //------------------------------------------------------------------------
  63. BOOL CW3ServerControl::SetServerState( DWORD dwControlCode )
  64. {
  65. CWrapMetaBase mb;
  66. BOOL fSuccess = FALSE;
  67. CString sz;
  68. DWORD err;
  69. // if the metabase doesn't init, then the app isn't running - lauch it
  70. if ( !mb.FInit() )
  71. return FALSE;
  72. // open the metabase object
  73. if ( !mb.Open(SZ_MB_INSTANCE_OBJECT, METADATA_PERMISSION_WRITE) )
  74. {
  75. err = GetLastError();
  76. sz.LoadString( IDS_MetaError );
  77. sz.Format( _T("%s\nError = %d"), sz, err );
  78. AfxMessageBox( sz );
  79. return FALSE;
  80. }
  81. // set the verb into the metabase
  82. if ( !mb.SetDword( _T(""), MD_SERVER_COMMAND, IIS_MD_UT_SERVER, dwControlCode ) )
  83. {
  84. err = GetLastError();
  85. sz.LoadString( IDS_MetaError );
  86. sz.Format( _T("%s\nError = %d"), sz, err );
  87. AfxMessageBox( sz );
  88. }
  89. else
  90. fSuccess = TRUE;
  91. // close the object
  92. mb.Close();
  93. // return the success flag
  94. return fSuccess;
  95. }
  96. //------------------------------------------------------------------------
  97. BOOL CW3ServerControl::StartServer( BOOL fOutputCommandLineInfo )
  98. {
  99. // just set the state in the metabase to do our thing
  100. return SetServerState( MD_SERVER_COMMAND_START );
  101. }
  102. //------------------------------------------------------------------------
  103. BOOL CW3ServerControl::W95LaunchInetInfo()
  104. {
  105. // start it
  106. return W95StartW3SVC();
  107. }
  108. //------------------------------------------------------------------------
  109. BOOL CW3ServerControl::StopServer( BOOL fOutputCommandLineInfo )
  110. {
  111. // just set the state in the metabase to do our thing
  112. return SetServerState( MD_SERVER_COMMAND_STOP );
  113. }
  114. //------------------------------------------------------------------------
  115. BOOL CW3ServerControl::PauseServer()
  116. {
  117. // note that inetinfo must be running for this to work
  118. // in either case, we now just pause the server
  119. return SetServerState( MD_SERVER_COMMAND_PAUSE );
  120. }
  121. //------------------------------------------------------------------------
  122. BOOL CW3ServerControl::ContinueServer()
  123. {
  124. // note that inetinfo must be running for this to work
  125. // in either case, we now just pause the server
  126. return SetServerState( MD_SERVER_COMMAND_CONTINUE );
  127. }
  128. //------------------------------------------------------------------------
  129. // get the inetinfo path
  130. BOOL CW3ServerControl::GetServerDirectory( CString &sz )
  131. {
  132. HKEY hKey;
  133. TCHAR chBuff[MAX_PATH+1];
  134. DWORD err, type;
  135. DWORD cbBuff;
  136. // get the server install path from the registry
  137. // open the registry key, if it exists
  138. err = RegOpenKeyEx(
  139. HKEY_LOCAL_MACHINE, // handle of open key
  140. REGKEY_STP, // address of name of subkey to open
  141. 0, // reserved
  142. KEY_READ, // security access mask
  143. &hKey // address of handle of open key
  144. );
  145. // if we did not open the key for any reason (say... it doesn't exist)
  146. // then leave right away
  147. if ( err != ERROR_SUCCESS )
  148. return FALSE;
  149. cbBuff = sizeof(chBuff);
  150. type = REG_SZ;
  151. err = RegQueryValueEx(
  152. hKey, // handle of key to query
  153. REGKEY_INSTALLKEY, // address of name of value to query
  154. NULL, // reserved
  155. &type, // address of buffer for value type
  156. (PUCHAR)chBuff, // address of data buffer
  157. &cbBuff // address of data buffer size
  158. );
  159. // close the key
  160. RegCloseKey( hKey );
  161. // if we did get the key for any reason (say... it doesn't exist)
  162. // then leave right away
  163. if ( err != ERROR_SUCCESS )
  164. return FALSE;
  165. // set the string
  166. sz = chBuff;
  167. // success
  168. return TRUE;
  169. }