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.

190 lines
4.6 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*************************************************************************
  3. *
  4. * RESET.C
  5. * This module is the RESET utility code.
  6. *
  7. *
  8. *************************************************************************/
  9. #include <stdio.h>
  10. #include <windows.h>
  11. //#include <ntddkbd.h>
  12. //#include <ntddmou.h>
  13. #include <winstaw.h>
  14. #include <regapi.h>
  15. #include <stdlib.h>
  16. #include <time.h>
  17. #include <utilsub.h>
  18. #include <process.h>
  19. #include <string.h>
  20. #include <malloc.h>
  21. #include <locale.h>
  22. #include <winnlsp.h>
  23. #include "reset.h"
  24. // max length of the locale string
  25. #define MAX_LOCALE_STRING 64
  26. /*-----------------------------------------------------------------------
  27. -- Supported commands (now obtained from registry)
  28. ------------------------------------------------------------------------*/
  29. PPROGRAMCALL pProgList = NULL;
  30. /*
  31. * Local function prototypes.
  32. */
  33. void Usage( BOOLEAN bError );
  34. /*************************************************************************
  35. *
  36. * main
  37. * Main function and entry point of the text-based RESET
  38. * menu utility.
  39. *
  40. * ENTRY:
  41. * argc (input)
  42. * count of the command line arguments.
  43. * argv (input)
  44. * vector of strings containing the command line arguments;
  45. * (not used due to always being ANSI strings).
  46. *
  47. * EXIT
  48. * (int) exit code: SUCCESS for success; FAILURE for error.
  49. *
  50. *************************************************************************/
  51. int __cdecl
  52. main( INT argc,
  53. CHAR **argv )
  54. {
  55. PWCHAR arg, *argvW;
  56. PPROGRAMCALL pProg, pProgramCall = NULL;
  57. size_t len;
  58. int status = FAILURE;
  59. LONG regstatus;
  60. WCHAR wszString[MAX_LOCALE_STRING + 1];
  61. setlocale(LC_ALL, ".OCP");
  62. // We don't want LC_CTYPE set the same as the others or else we will see
  63. // garbage output in the localized version, so we need to explicitly
  64. // set it to correct console output code page
  65. _snwprintf(wszString, sizeof(wszString)/sizeof(WCHAR), L".%d", GetConsoleOutputCP());
  66. wszString[sizeof(wszString)/sizeof(WCHAR) - 1] = L'\0';
  67. _wsetlocale(LC_CTYPE, wszString);
  68. SetThreadUILanguage(0);
  69. /*
  70. * Obtain the supported RESET commands from registry.
  71. */
  72. if ( (regstatus =
  73. RegQueryUtilityCommandList( UTILITY_REG_NAME_RESET, &pProgList ))
  74. != ERROR_SUCCESS ) {
  75. ErrorPrintf(IDS_ERROR_REGISTRY_FAILURE, UTILITY_NAME, regstatus);
  76. goto exit;
  77. }
  78. /*
  79. * Massage the command line.
  80. */
  81. argvW = MassageCommandLine((DWORD)argc);
  82. if (argvW == NULL) {
  83. ErrorPrintf(IDS_ERROR_MALLOC);
  84. goto exit;
  85. }
  86. /*
  87. * Check for valid utility name and execute.
  88. */
  89. if ( argc > 1 && *(argvW[1]) ) {
  90. len = wcslen(arg = argvW[1]);
  91. for ( pProg = pProgList->pFirst; pProg != NULL; pProg = pProg->pNext ) {
  92. if ( (len >= pProg->CommandLen) &&
  93. !_wcsnicmp( arg, pProg->Command, len ) ) {
  94. pProgramCall = pProg;
  95. break;
  96. }
  97. }
  98. if ( pProgramCall ) {
  99. if ( ExecProgram(pProgramCall, argc - 2, &argvW[2]) )
  100. goto exit;
  101. } else if ( ((arg[0] == L'-') || (arg[0] == L'/')) &&
  102. (arg[1] == L'?') ) {
  103. /*
  104. * Help requested.
  105. */
  106. Usage(FALSE);
  107. status = SUCCESS;
  108. goto exit;
  109. } else {
  110. /*
  111. * Bad command line.
  112. */
  113. Usage(TRUE);
  114. goto exit;
  115. }
  116. } else {
  117. /*
  118. * Nothing on command line.
  119. */
  120. Usage(TRUE);
  121. goto exit;
  122. }
  123. exit:
  124. if ( pProgList )
  125. RegFreeUtilityCommandList(pProgList); // let's be tidy
  126. return(status);
  127. } /* main() */
  128. /*******************************************************************************
  129. *
  130. * Usage
  131. *
  132. * Output the usage message for this utility.
  133. *
  134. * ENTRY:
  135. * bError (input)
  136. * TRUE if the 'invalid parameter(s)' message should preceed the usage
  137. * message and the output go to stderr; FALSE for no such error
  138. * string and output goes to stdout.
  139. *
  140. * EXIT:
  141. *
  142. *
  143. ******************************************************************************/
  144. void
  145. Usage( BOOLEAN bError )
  146. {
  147. if ( bError ) {
  148. ErrorPrintf(IDS_ERROR_INVALID_PARAMETERS);
  149. }
  150. ProgramUsage(UTILITY_NAME, pProgList, bError);
  151. } /* Usage() */