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.

135 lines
4.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  4. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  5. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  6. // PARTICULAR PURPOSE.
  7. //
  8. // Copyright 1998 Microsoft Corporation. All Rights Reserved.
  9. //
  10. // PROGRAM: ChgState.cxx
  11. //
  12. // PURPOSE: To change the state of a catalog (on local machine)
  13. //
  14. // PLATFORM: Windows NT
  15. //
  16. //--------------------------------------------------------------------------
  17. //+-------------------------------------------------------------------------
  18. //
  19. // Function: wmain
  20. //
  21. // Synopsis: Entry point for the app.
  22. //
  23. // Arguments: [argc] - Argument count
  24. // [argv] - Arguments
  25. //
  26. //--------------------------------------------------------------------------
  27. #include <stdio.h>
  28. #include <windows.h>
  29. #include <ntquery.h>
  30. //+-------------------------------------------------------------------------
  31. //
  32. // Function: Usage
  33. //
  34. // Synopsis: Displays information about how to use the app and exits
  35. //
  36. //--------------------------------------------------------------------------
  37. void Usage()
  38. {
  39. printf( "Usage: ChgState /a:<RO|RW|Stop|GetState> /c:<Catalog Name>\n" );
  40. printf( " /m:<Machine Name>\n\n" );
  41. printf( " ChgState Change the state of a catalog\n" );
  42. printf( " /a:<Action> the action to be taken, default is RO\n" );
  43. printf( " The three actions are states RO (ReadOnly), RW (Read\\Write)\n" );
  44. printf( " and Stop (Stopped)\n" );
  45. printf( " You can also specify GetState to check the state of a catalog\n" );
  46. printf( " /c:<Catalog Name> name of the catalog, default is SYSTEM\n" );
  47. printf( " /m:<Machine Name> name of the machine, default is local machine\n" );
  48. exit( -1 );
  49. } //Usage
  50. extern "C" int __cdecl wmain( int argc, WCHAR * argv[] )
  51. {
  52. WCHAR const * pwcsCatalog = L"system"; // default: system
  53. WCHAR const * pwcsMachine = L"."; // default: local machine
  54. WCHAR const * pwcsAction = L"RO"; // default: ReadOnly
  55. DWORD dwNewState = CICAT_READONLY;
  56. DWORD dwOldState;
  57. SCODE sc = S_OK;
  58. // Parse the command for arguments
  59. if ( argc > 1 )
  60. {
  61. for ( int i = 1; i < argc; i++ )
  62. {
  63. if ( L'/' == argv[i][0] )
  64. {
  65. WCHAR wc = (WCHAR) toupper( argv[i][1] );
  66. if ( ':' != argv[i][2] )
  67. Usage();
  68. if ( 'A' == wc )
  69. pwcsAction = argv[i] + 3;
  70. else if ( 'C' == wc )
  71. pwcsCatalog = argv[i] + 3;
  72. else if ( 'M' == wc )
  73. pwcsMachine = argv[i] + 3;
  74. else
  75. Usage();
  76. }
  77. else
  78. Usage();
  79. }
  80. }
  81. else
  82. {
  83. Usage();
  84. }
  85. if ( !wcscmp( pwcsAction, L"RO" ) ) // ReadOnly
  86. dwNewState = CICAT_READONLY;
  87. else if ( !wcscmp( pwcsAction, L"RW" ) ) // ReadWrite
  88. dwNewState = CICAT_WRITABLE;
  89. else if ( !wcscmp( pwcsAction, L"Stop" ) ) // Stop
  90. dwNewState = CICAT_STOPPED;
  91. else if ( !wcscmp( pwcsAction, L"GetState" ) ) // Get the current state
  92. dwNewState = CICAT_GET_STATE;
  93. else
  94. {
  95. fprintf( stderr, "Action undefined!\n" );
  96. exit(-1);
  97. }
  98. // call the API
  99. sc = SetCatalogState ( pwcsCatalog,
  100. pwcsMachine,
  101. dwNewState,
  102. &dwOldState );
  103. if ( FAILED( sc ) )
  104. {
  105. printf( "ChangeState for catalog %ws failed with error %#x\n", pwcsCatalog ,sc );
  106. return -1;
  107. }
  108. printf(" Old State is " );
  109. if ( CICAT_STOPPED == dwOldState )
  110. printf( "CICAT_STOPPED.\n" );
  111. else
  112. {
  113. if ( CICAT_WRITABLE & dwOldState )
  114. printf( "CICAT_WRITABLE.\n" );
  115. else if ( CICAT_READONLY & dwOldState )
  116. printf( "CICAT_READONLY.\n" );
  117. else printf( "Error obtaining oldState. The return value is %d\n", dwOldState );
  118. }
  119. return 0;
  120. } //wmain