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.

400 lines
9.0 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1993-1994
  4. *
  5. * TITLE: REGMAIN.C
  6. *
  7. * VERSION: 4.01
  8. *
  9. * AUTHOR: Tracy Sharpe
  10. *
  11. * DATE: 05 Mar 1994
  12. *
  13. *******************************************************************************/
  14. #include "pch.h"
  15. #include <regstr.h>
  16. #include "regedit.h"
  17. #include "regfile.h"
  18. #include "regbined.h"
  19. #include "regresid.h"
  20. // Instance handle of this application.
  21. HINSTANCE g_hInstance;
  22. // TRUE if accelerator table should not be used, such as during a rename
  23. // operation.
  24. BOOL g_fDisableAccelerators = FALSE;
  25. TCHAR g_KeyNameBuffer[MAXKEYNAME];
  26. TCHAR g_ValueNameBuffer[MAXVALUENAME_LENGTH];
  27. COLORREF g_clrWindow;
  28. COLORREF g_clrWindowText;
  29. COLORREF g_clrHighlight;
  30. COLORREF g_clrHighlightText;
  31. HWND g_hRegEditWnd;
  32. PTSTR g_pHelpFileName;
  33. TCHAR g_NullString[] = TEXT("");
  34. #define PARSERET_CONTINUE 0
  35. #define PARSERET_REFRESH 1
  36. #define PARSERET_EXIT 2
  37. UINT
  38. PASCAL
  39. ParseCommandLine(
  40. VOID
  41. );
  42. BOOL
  43. PASCAL
  44. IsRegistryToolDisabled(
  45. VOID
  46. );
  47. int
  48. PASCAL
  49. ModuleEntry(
  50. VOID
  51. )
  52. {
  53. HWND hPopupWnd;
  54. HACCEL hRegEditAccel;
  55. MSG Msg;
  56. USHORT wLanguageId = LANGIDFROMLCID(GetThreadLocale());
  57. INITCOMMONCONTROLSEX icce;
  58. g_hInstance = GetModuleHandle(NULL);
  59. icce.dwSize = sizeof(icce);
  60. icce.dwICC = ICC_ALL_CLASSES;
  61. InitCommonControlsEx(&icce);
  62. g_hRegEditWnd = FindWindow(g_RegEditClassName, NULL);
  63. //
  64. // To prevent users from corrupting their registries,
  65. // administrators can set a policy switch to prevent editing. Check that
  66. // switch now.
  67. //
  68. if (IsRegistryToolDisabled())
  69. {
  70. InternalMessageBox(g_hInstance, NULL, MAKEINTRESOURCE(IDS_REGEDITDISABLED),
  71. MAKEINTRESOURCE(IDS_REGEDIT), MB_ICONERROR | MB_OK);
  72. goto ModuleExit;
  73. }
  74. //
  75. // Check if we were given a commandline and handle if appropriate.
  76. //
  77. switch (ParseCommandLine()) {
  78. case PARSERET_REFRESH:
  79. if (g_hRegEditWnd != NULL)
  80. PostMessage(g_hRegEditWnd, WM_COMMAND, ID_REFRESH, 0);
  81. // FALL THROUGH
  82. case PARSERET_EXIT:
  83. goto ModuleExit;
  84. }
  85. //
  86. // Allow only one instance of the Registry Editor.
  87. //
  88. if (g_hRegEditWnd != NULL) {
  89. if (IsIconic(g_hRegEditWnd))
  90. ShowWindow(g_hRegEditWnd, SW_RESTORE);
  91. else {
  92. BringWindowToTop(g_hRegEditWnd);
  93. if ((hPopupWnd = GetLastActivePopup(g_hRegEditWnd)) != g_hRegEditWnd)
  94. BringWindowToTop(hPopupWnd);
  95. SetForegroundWindow(hPopupWnd);
  96. }
  97. goto ModuleExit;
  98. }
  99. //
  100. // Initialize and create an instance of the Registry Editor window.
  101. //
  102. if ((g_pHelpFileName = LoadDynamicString(IDS_HELPFILENAME)) == NULL)
  103. goto ModuleExit;
  104. if (!RegisterRegEditClass() || !RegisterHexEditClass())
  105. goto ModuleExit;
  106. if ((hRegEditAccel = LoadAccelerators(g_hInstance,
  107. MAKEINTRESOURCE(IDACCEL_REGEDIT))) == NULL)
  108. goto ModuleExit;
  109. if ((g_hRegEditWnd = CreateRegEditWnd()) != NULL) {
  110. while (GetMessage(&Msg, NULL, 0, 0)) {
  111. if (g_fDisableAccelerators || !TranslateAccelerator(g_hRegEditWnd,
  112. hRegEditAccel, &Msg)) {
  113. TranslateMessage(&Msg);
  114. DispatchMessage(&Msg);
  115. }
  116. }
  117. }
  118. ModuleExit:
  119. ExitProcess(0);
  120. return 0;
  121. }
  122. /*******************************************************************************
  123. *
  124. * ParseCommandline
  125. *
  126. * DESCRIPTION:
  127. *
  128. * PARAMETERS:
  129. * (returns), TRUE to continuing loading, else FALSE to stop immediately.
  130. *
  131. *******************************************************************************/
  132. UINT
  133. PASCAL
  134. ParseCommandLine(
  135. VOID
  136. )
  137. {
  138. BOOL fSilentMode;
  139. BOOL fExportMode;
  140. LPTSTR lpCmdLine;
  141. LPTSTR lpFileName;
  142. LPTSTR lpSelectedPath;
  143. fSilentMode = FALSE;
  144. fExportMode = FALSE;
  145. lpCmdLine = GetCommandLine();
  146. //
  147. // Skip past the application pathname. Be sure to handle long filenames
  148. // correctly.
  149. //
  150. if (*lpCmdLine == TEXT('\"')) {
  151. do
  152. lpCmdLine = CharNext(lpCmdLine);
  153. while (*lpCmdLine != 0 && *lpCmdLine != TEXT('\"'));
  154. if (*lpCmdLine == TEXT('\"'))
  155. lpCmdLine = CharNext(lpCmdLine);
  156. }
  157. else {
  158. while (*lpCmdLine > TEXT(' '))
  159. lpCmdLine = CharNext(lpCmdLine);
  160. }
  161. while (*lpCmdLine != 0 && *lpCmdLine <= TEXT(' '))
  162. lpCmdLine = CharNext(lpCmdLine);
  163. while (TRUE) {
  164. while (*lpCmdLine == TEXT(' '))
  165. lpCmdLine = CharNext(lpCmdLine);
  166. if (*lpCmdLine != TEXT('/') && *lpCmdLine != TEXT('-'))
  167. break;
  168. lpCmdLine = CharNext(lpCmdLine);
  169. while (*lpCmdLine != 0 && *lpCmdLine != TEXT(' ')) {
  170. switch (*lpCmdLine) {
  171. case TEXT('m'):
  172. case TEXT('M'):
  173. //
  174. // Allow multiple instances mode. Pretend we are the only
  175. // copy of regedit running.
  176. //
  177. g_hRegEditWnd = NULL;
  178. break;
  179. //
  180. // Specifies the location of the SYSTEM.DAT and USER.DAT
  181. // files in real-mode. We don't use these switches, but
  182. // we do need to bump past the filename.
  183. //
  184. case TEXT('l'):
  185. case TEXT('L'):
  186. case TEXT('r'):
  187. case TEXT('R'):
  188. return PARSERET_EXIT;
  189. case TEXT('e'):
  190. case TEXT('E'):
  191. fExportMode = TRUE;
  192. break;
  193. case TEXT('a'):
  194. case TEXT('A'):
  195. fExportMode = TRUE;
  196. g_RegEditData.uExportFormat = FILE_TYPE_REGEDIT4;
  197. break;
  198. case TEXT('s'):
  199. case TEXT('S'):
  200. //
  201. // Silent mode where we don't show any dialogs when we
  202. // import a registry file script.
  203. //
  204. fSilentMode = TRUE;
  205. break;
  206. case TEXT('v'):
  207. case TEXT('V'):
  208. //
  209. // With the Windows 3.1 Registry Editor, this brought up
  210. // the tree-style view. Now we always show the tree so
  211. // nothing to do here!
  212. //
  213. // FALL THROUGH
  214. case TEXT('u'):
  215. case TEXT('U'):
  216. //
  217. // Update, don't overwrite existing path entries in
  218. // shell\open\command or shell\open\print. This isn't even
  219. // used by the Windows 3.1 Registry Editor!
  220. //
  221. // FALL THROUGH
  222. default:
  223. break;
  224. }
  225. lpCmdLine = CharNext(lpCmdLine);
  226. }
  227. }
  228. if (!fExportMode) {
  229. if (*lpCmdLine == 0)
  230. return PARSERET_CONTINUE;
  231. else {
  232. lpFileName = GetNextSubstring(lpCmdLine);
  233. while (lpFileName != NULL) {
  234. RegEdit_ImportRegFile(NULL, fSilentMode, lpFileName, NULL);
  235. lpFileName = GetNextSubstring(NULL);
  236. }
  237. return PARSERET_REFRESH;
  238. }
  239. }
  240. else {
  241. lpFileName = GetNextSubstring(lpCmdLine);
  242. lpSelectedPath = GetNextSubstring(NULL);
  243. if (GetNextSubstring(NULL) == NULL)
  244. RegEdit_ExportRegFile(NULL, fSilentMode, lpFileName, lpSelectedPath);
  245. return PARSERET_EXIT;
  246. }
  247. }
  248. /*******************************************************************************
  249. *
  250. * IsRegistryToolDisabled
  251. *
  252. * DESCRIPTION:
  253. * Checks the policy section of the registry to see if registry editing
  254. * tools should be disabled. This switch is set by administrators to
  255. * protect novice users.
  256. *
  257. * The Registry Editor is disabled if and only if this value exists and is
  258. * set.
  259. *
  260. * PARAMETERS:
  261. * (returns), TRUE if registry tool should not be run, else FALSE.
  262. *
  263. *******************************************************************************/
  264. BOOL
  265. PASCAL
  266. IsRegistryToolDisabled(
  267. VOID
  268. )
  269. {
  270. BOOL fRegistryToolDisabled;
  271. HKEY hKey;
  272. DWORD Type;
  273. DWORD ValueBuffer;
  274. DWORD cbValueBuffer;
  275. fRegistryToolDisabled = FALSE;
  276. if (RegOpenKey(HKEY_CURRENT_USER,
  277. REGSTR_PATH_POLICIES TEXT("\\") REGSTR_KEY_SYSTEM,
  278. &hKey) == ERROR_SUCCESS)
  279. {
  280. cbValueBuffer = sizeof(DWORD);
  281. if (RegEdit_QueryValueEx(hKey, REGSTR_VAL_DISABLEREGTOOLS, NULL, &Type,
  282. (LPSTR) &ValueBuffer, &cbValueBuffer) == ERROR_SUCCESS)
  283. {
  284. if (Type == REG_DWORD && cbValueBuffer == sizeof(DWORD) &&
  285. ValueBuffer != FALSE)
  286. fRegistryToolDisabled = TRUE;
  287. }
  288. RegCloseKey(hKey);
  289. }
  290. return fRegistryToolDisabled;
  291. }