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.

209 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. extern "C" {
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. }
  18. #include <dbgutil.h>
  19. #include <ole2.h>
  20. #include <windows.h>
  21. //#include <coiadm.hxx>
  22. //#include <admacl.hxx>
  23. #include <iiscnfg.h>
  24. //#include <secpriv.h>
  25. //#include <globlist.hxx>
  26. #include <buffer.hxx>
  27. #include <string.hxx>
  28. #include <pwsctrl.h>
  29. #include <shellapi.h>
  30. #include <pwsdata.hxx>
  31. #include <inetsvcs.h>
  32. #define REGKEY_STP TEXT("SOFTWARE\\Microsoft\\INetStp")
  33. #define REGKEY_INSTALLKEY TEXT("InstallPath")
  34. //------------------------------------------------------------------------
  35. //BOOL W95StartW3SVC( LPCSTR pszPath, LPCSTR pszPathDir, PCHAR pszParams )
  36. BOOL W95StartW3SVC( void )
  37. {
  38. HKEY hKey;
  39. TCHAR chPath[MAX_PATH+1];
  40. DWORD cbPath;
  41. DWORD err, type;
  42. STR strPath;
  43. // get the server install path from the registry
  44. // open the registry key, if it exists
  45. err = RegOpenKeyEx(
  46. HKEY_LOCAL_MACHINE, // handle of open key
  47. REGKEY_STP, // address of name of subkey to open
  48. 0, // reserved
  49. KEY_READ, // security access mask
  50. &hKey // address of handle of open key
  51. );
  52. // if we did not open the key for any reason (say... it doesn't exist)
  53. // then leave right away
  54. if ( err != ERROR_SUCCESS )
  55. return FALSE;
  56. cbPath = sizeof(chPath);
  57. type = REG_SZ;
  58. err = RegQueryValueEx(
  59. hKey, // handle of key to query
  60. REGKEY_INSTALLKEY, // address of name of value to query
  61. NULL, // reserved
  62. &type, // address of buffer for value type
  63. (PUCHAR)chPath, // address of data buffer
  64. &cbPath // address of data buffer size
  65. );
  66. // close the key
  67. RegCloseKey( hKey );
  68. // if we did get the key for any reason (say... it doesn't exist)
  69. // then leave right away
  70. if ( err != ERROR_SUCCESS )
  71. return FALSE;
  72. // add on the file name
  73. if (strPath.Copy(chPath)) {
  74. if (strPath.Append("\\inetinfo.exe")) {
  75. // and do it to it!
  76. ULONG_PTR res = (ULONG_PTR)ShellExecute(
  77. NULL, // handle to parent window
  78. NULL, // pointer to string that specifies operation to perform
  79. strPath.QueryStr(), // pointer to filename or folder name string
  80. "-e w3svc", // pointer to string that specifies executable-file parameters
  81. NULL, // pointer to string that specifies default directory
  82. SW_HIDE // whether file is shown when opened
  83. );
  84. return ( res > 32 );
  85. }
  86. }
  87. return FALSE;
  88. }
  89. //------------------------------------------------------------------------
  90. BOOL
  91. W95ShutdownW3SVC(
  92. VOID
  93. )
  94. {
  95. HANDLE hEvent;
  96. hEvent = CreateEvent(NULL, TRUE, FALSE, "Inet_shutdown");
  97. if ( hEvent == NULL ) {
  98. return TRUE; // not there
  99. }
  100. if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
  101. SetEvent( hEvent );
  102. }
  103. CloseHandle(hEvent);
  104. return TRUE;
  105. }
  106. //------------------------------------------------------------------------
  107. BOOL
  108. W95ShutdownIISADMIN(
  109. VOID
  110. )
  111. {
  112. DWORD i;
  113. HANDLE hEvent;
  114. hEvent = CreateEvent(NULL, TRUE, FALSE, IIS_AS_EXE_OBJECT_NAME);
  115. if ( hEvent == NULL ) {
  116. return(TRUE);
  117. }
  118. if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
  119. SetEvent( hEvent );
  120. }
  121. CloseHandle(hEvent);
  122. for (i=0; i < 20; i++) {
  123. hEvent = CreateEvent(NULL, TRUE, FALSE, IIS_AS_EXE_OBJECT_NAME);
  124. if ( hEvent != NULL ) {
  125. DWORD err = GetLastError();
  126. CloseHandle(hEvent);
  127. if ( err == ERROR_ALREADY_EXISTS ) {
  128. Sleep(500);
  129. continue;
  130. }
  131. }
  132. break;
  133. }
  134. return(TRUE);
  135. }
  136. //------------------------------------------------------------------------
  137. BOOL
  138. IsIISAdminRunning(
  139. VOID
  140. )
  141. {
  142. HANDLE hEvent;
  143. BOOL fFound = FALSE;
  144. hEvent = CreateEvent(NULL, TRUE, FALSE, IIS_AS_EXE_OBJECT_NAME);
  145. if ( hEvent != NULL ) {
  146. fFound = (GetLastError() == ERROR_ALREADY_EXISTS);
  147. CloseHandle(hEvent);
  148. }
  149. return(fFound);
  150. }
  151. //------------------------------------------------------------------------
  152. BOOL
  153. IsInetinfoRunning(
  154. VOID
  155. )
  156. {
  157. HANDLE hEvent;
  158. BOOL fFound = FALSE;
  159. hEvent = CreateEvent(NULL, TRUE, FALSE, PWS_SHUTDOWN_EVENT);
  160. if ( hEvent != NULL ) {
  161. fFound = (GetLastError() == ERROR_ALREADY_EXISTS);
  162. CloseHandle(hEvent);
  163. }
  164. return(fFound);
  165. }