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.

219 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. pwsctrl.cpp
  5. Abstract:
  6. This is the main routine for the Internet Services suite.
  7. Author:
  8. Johnson Apacible (JohnsonA) 29-Apr-1997
  9. Boyd Multerer (BoydM) 29-Apr-1997
  10. --*/
  11. #include "stdafx.h"
  12. #include "resource.h"
  13. #include <pwsdata.hxx>
  14. #include <inetsvcs.h>
  15. #include "pwsctrl.h"
  16. #define REGKEY_STP _T("SOFTWARE\\Microsoft\\INetStp")
  17. #define REGKEY_INSTALLKEY _T("InstallPath")
  18. //------------------------------------------------------------------------
  19. //BOOL W95StartW3SVC( LPCSTR pszPath, LPCSTR pszPathDir, PCHAR pszParams )
  20. BOOL W95StartW3SVC( void )
  21. {
  22. HKEY hKey;
  23. TCHAR chPath[MAX_PATH+1];
  24. DWORD cbPath;
  25. DWORD err, type;
  26. // get the server install path from the registry
  27. // open the registry key, if it exists
  28. err = RegOpenKeyEx(
  29. HKEY_LOCAL_MACHINE, // handle of open key
  30. REGKEY_STP, // address of name of subkey to open
  31. 0, // reserved
  32. KEY_READ, // security access mask
  33. &hKey // address of handle of open key
  34. );
  35. // if we did not open the key for any reason (say... it doesn't exist)
  36. // then leave right away
  37. if ( err != ERROR_SUCCESS )
  38. return FALSE;
  39. cbPath = sizeof(chPath);
  40. type = REG_SZ;
  41. err = RegQueryValueEx(
  42. hKey, // handle of key to query
  43. REGKEY_INSTALLKEY, // address of name of value to query
  44. NULL, // reserved
  45. &type, // address of buffer for value type
  46. (PUCHAR)chPath, // address of data buffer
  47. &cbPath // address of data buffer size
  48. );
  49. // close the key
  50. RegCloseKey( hKey );
  51. // if we did get the key for any reason (say... it doesn't exist)
  52. // then leave right away
  53. if ( err != ERROR_SUCCESS )
  54. return FALSE;
  55. // add on the file name
  56. CString sz = chPath;
  57. sz += _T("\\inetinfo.exe");
  58. // and do it to it!
  59. HINSTANCE res = ShellExecute(
  60. NULL, // handle to parent window
  61. NULL, // pointer to string that specifies operation to perform
  62. sz, // pointer to filename or folder name string
  63. _T("-e w3svc"), // pointer to string that specifies executable-file parameters
  64. NULL, // pointer to string that specifies default directory
  65. SW_HIDE // whether file is shown when opened
  66. );
  67. return ( HandleToUlong(res) > 32 );
  68. /*
  69. STARTUPINFO startupInfo;
  70. PROCESS_INFORMATION processInfo;
  71. ZeroMemory(&startupInfo, sizeof(STARTUPINFO));
  72. startupInfo.cb = sizeof(STARTUPINFO);
  73. if ( !CreateProcess(
  74. pszPath,
  75. pszParams,
  76. NULL,
  77. NULL,
  78. FALSE,
  79. 0,
  80. NULL,
  81. pszPathDir,
  82. &startupInfo,
  83. &processInfo) )
  84. {
  85. printf("Create process failed with %d\n",
  86. GetLastError());
  87. return FALSE;
  88. }
  89. return TRUE;
  90. */
  91. }
  92. //------------------------------------------------------------------------
  93. BOOL
  94. W95ShutdownW3SVC(
  95. VOID
  96. )
  97. {
  98. DWORD i;
  99. HANDLE hEvent;
  100. hEvent = CreateEventA(NULL, TRUE, FALSE, PWS_SHUTDOWN_EVENT);
  101. if ( hEvent == NULL ) {
  102. return TRUE; // not there
  103. }
  104. if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
  105. SetEvent( hEvent );
  106. }
  107. CloseHandle(hEvent);
  108. for (i=0; i < 25; i++) {
  109. if ( IsInetinfoRunning() ) {
  110. Sleep(500);
  111. continue;
  112. }
  113. break;
  114. }
  115. return TRUE;
  116. }
  117. //------------------------------------------------------------------------
  118. BOOL
  119. W95ShutdownIISADMIN(
  120. VOID
  121. )
  122. {
  123. DWORD i;
  124. HANDLE hEvent;
  125. hEvent = CreateEvent(NULL, TRUE, FALSE, _T(IIS_AS_EXE_OBJECT_NAME));
  126. if ( hEvent == NULL ) {
  127. return(TRUE);
  128. }
  129. if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
  130. SetEvent( hEvent );
  131. }
  132. CloseHandle(hEvent);
  133. for (i=0; i < 20; i++) {
  134. if ( IsIISAdminRunning() ) {
  135. Sleep(500);
  136. continue;
  137. }
  138. break;
  139. }
  140. return(TRUE);
  141. }
  142. //------------------------------------------------------------------------
  143. BOOL
  144. IsIISAdminRunning(
  145. VOID
  146. )
  147. {
  148. HANDLE hEvent;
  149. BOOL fFound = FALSE;
  150. hEvent = CreateEvent(NULL, TRUE, FALSE, _T(IIS_AS_EXE_OBJECT_NAME));
  151. if ( hEvent != NULL ) {
  152. fFound = (GetLastError() == ERROR_ALREADY_EXISTS);
  153. CloseHandle(hEvent);
  154. }
  155. return(fFound);
  156. }
  157. //------------------------------------------------------------------------
  158. BOOL
  159. IsInetinfoRunning(
  160. VOID
  161. )
  162. {
  163. HANDLE hEvent;
  164. BOOL fFound = FALSE;
  165. hEvent = CreateEvent(NULL, TRUE, FALSE, _T(PWS_SHUTDOWN_EVENT));
  166. if ( hEvent != NULL ) {
  167. fFound = (GetLastError() == ERROR_ALREADY_EXISTS);
  168. CloseHandle(hEvent);
  169. }
  170. return(fFound);
  171. }