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.

245 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. main.cxx
  5. Abstract:
  6. Server Instance Controller.
  7. Author:
  8. Keith Moore (keithmo) 05-Feb-1997
  9. Revision History:
  10. --*/
  11. #include "precomp.hxx"
  12. #pragma hdrstop
  13. //
  14. // Private constants.
  15. //
  16. #define TEST_HRESULT(api,hr,fatal) \
  17. if( FAILED(hr) ) { \
  18. \
  19. wprintf( \
  20. L"%S:%lu failed, error %lx %S\n", \
  21. (api), \
  22. __LINE__, \
  23. (result), \
  24. (fatal) \
  25. ? "ABORTING" \
  26. : "CONTINUING" \
  27. ); \
  28. \
  29. if( fatal ) { \
  30. \
  31. goto cleanup; \
  32. \
  33. } \
  34. \
  35. } else
  36. //
  37. // Private types.
  38. //
  39. //
  40. // Private globals.
  41. //
  42. COMMAND_TABLE CommandTable[] =
  43. {
  44. { L"Start", &StartCommand },
  45. { L"Stop", &StopCommand },
  46. { L"Pause", &PauseCommand },
  47. { L"Continue", &ContinueCommand },
  48. { L"Query", &QueryCommand }
  49. };
  50. #define NUM_COMMANDS ( sizeof(CommandTable) / sizeof(CommandTable[0]) )
  51. //
  52. // Private prototypes.
  53. //
  54. VOID
  55. Usage(
  56. VOID
  57. );
  58. //
  59. // Public functions.
  60. //
  61. INT
  62. __cdecl
  63. wmain(
  64. IN INT argc,
  65. IN LPWSTR argv[]
  66. )
  67. {
  68. HRESULT result;
  69. ADMIN_SINK * sink;
  70. IMSAdminBase * admCom;
  71. DWORD i;
  72. PCOMMAND_TABLE command;
  73. //
  74. // Setup locals so we know how to cleanup on exit.
  75. //
  76. admCom = NULL;
  77. sink = NULL;
  78. //
  79. // Validate the arguments.
  80. //
  81. if( argc == 1 ) {
  82. Usage();
  83. return 1;
  84. }
  85. for( i = 0, command = CommandTable ;
  86. i < NUM_COMMANDS ;
  87. i++, command++ ) {
  88. if( !_wcsicmp( argv[1], command->Name ) ) {
  89. break;
  90. }
  91. }
  92. if( i == NUM_COMMANDS ) {
  93. Usage();
  94. return 1;
  95. }
  96. argc -= 2; // Skip the program name...
  97. argv += 2; // ...and the command name.
  98. //
  99. // Initialize COM.
  100. //
  101. result = CoInitializeEx(
  102. NULL,
  103. COINIT_MULTITHREADED
  104. );
  105. TEST_HRESULT( "CoInitializeEx()", result, TRUE );
  106. //
  107. // Get the admin object.
  108. //
  109. result = MdGetAdminObject( &admCom );
  110. TEST_HRESULT( "MdGetAdminObject()", result, TRUE );
  111. //
  112. // Setup the advise sink.
  113. //
  114. sink = new ADMIN_SINK();
  115. if( sink == NULL ) {
  116. result = HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
  117. } else {
  118. sink->AddRef();
  119. result = sink->Initialize( (IUnknown *)admCom );
  120. }
  121. TEST_HRESULT( "sink->Initialize()", result, TRUE );
  122. //
  123. // Let the command handler do the dirty work.
  124. //
  125. command->Handler(
  126. admCom,
  127. sink,
  128. argc,
  129. argv
  130. );
  131. cleanup:
  132. if( sink != NULL ) {
  133. sink->Unadvise();
  134. sink->Release();
  135. }
  136. //
  137. // Release the admin object.
  138. //
  139. if( admCom != NULL ) {
  140. result = MdReleaseAdminObject( admCom );
  141. TEST_HRESULT( "MdReleaseAdminObject()", result, FALSE );
  142. }
  143. //
  144. // Shutdown COM.
  145. //
  146. CoUninitialize();
  147. return 0;
  148. } // main
  149. //
  150. // Private functions.
  151. //
  152. VOID
  153. Usage(
  154. VOID
  155. )
  156. {
  157. wprintf(
  158. L"Use: iisnet operation service/instance\n"
  159. L"\n"
  160. L"Valid operations are:\n"
  161. L"\n"
  162. L" start\n"
  163. L" stop\n"
  164. L" pause\n"
  165. L" continue\n"
  166. L" query\n"
  167. L"\n"
  168. L"For example:\n"
  169. L"\n"
  170. L" iisnet pause w3svc/1\n"
  171. );
  172. } // Usage