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.

134 lines
4.1 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-1999 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 2000
  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 (Read Only), RW (Read\\Write) and Stop (Stopped)\n" );
  44. printf( " You can also specify GetState to check the state of a catalog\n" );
  45. printf( " /c:<Catalog Name> name of the catalog, default is SYSTEM\n" );
  46. printf( " /m:<Machine Name> name of the machine, default is local machine\n" );
  47. exit( -1 );
  48. } //Usage
  49. extern "C" int __cdecl wmain( int argc, WCHAR * argv[] )
  50. {
  51. WCHAR const * pwcsCatalog = L"system"; // default: system
  52. WCHAR const * pwcsMachine = L"."; // default: local machine
  53. WCHAR const * pwcsAction = L"RO"; // default: ReadOnly
  54. DWORD dwNewState = CICAT_READONLY;
  55. DWORD dwOldState;
  56. SCODE sc = S_OK;
  57. // Parse the command for arguments
  58. if ( argc > 1 )
  59. {
  60. for ( int i = 1; i < argc; i++ )
  61. {
  62. if ( L'/' == argv[i][0] )
  63. {
  64. WCHAR wc = (WCHAR) toupper( argv[i][1] );
  65. if ( ':' != argv[i][2] )
  66. Usage();
  67. if ( 'A' == wc )
  68. pwcsAction = argv[i] + 3;
  69. else if ( 'C' == wc )
  70. pwcsCatalog = argv[i] + 3;
  71. else if ( 'M' == wc )
  72. pwcsMachine = argv[i] + 3;
  73. else
  74. Usage();
  75. }
  76. else
  77. Usage();
  78. }
  79. }
  80. else
  81. {
  82. Usage();
  83. }
  84. if ( !wcscmp( pwcsAction, L"RO" ) ) // ReadOnly
  85. dwNewState = CICAT_READONLY;
  86. else if ( !wcscmp( pwcsAction, L"RW" ) ) // ReadWrite
  87. dwNewState = CICAT_WRITABLE;
  88. else if ( !wcscmp( pwcsAction, L"Stop" ) ) // Stop
  89. dwNewState = CICAT_STOPPED;
  90. else if ( !wcscmp( pwcsAction, L"GetState" ) ) // Get the current state
  91. dwNewState = CICAT_GET_STATE;
  92. else
  93. {
  94. fprintf( stderr, "Action undefined!\n" );
  95. exit(-1);
  96. }
  97. // call the API
  98. sc = SetCatalogState ( pwcsCatalog,
  99. pwcsMachine,
  100. dwNewState,
  101. &dwOldState );
  102. if ( FAILED( sc ) )
  103. {
  104. printf( "ChangeState for catalog %ws failed with error %#x\n", pwcsCatalog ,sc );
  105. return -1;
  106. }
  107. printf(" Old State is " );
  108. if ( CICAT_STOPPED == dwOldState )
  109. printf( "CICAT_STOPPED.\n" );
  110. else
  111. {
  112. if ( CICAT_WRITABLE & dwOldState )
  113. printf( "CICAT_WRITABLE.\n" );
  114. else if ( CICAT_READONLY & dwOldState )
  115. printf( "CICAT_READONLY.\n" );
  116. else printf( "Error obtaining oldState. The return value is %d\n", dwOldState );
  117. }
  118. return 0;
  119. } //wmain