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.

119 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 1990-1994 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. SplInit.c
  6. Abstract:
  7. Initialize the spooler.
  8. Author:
  9. Environment:
  10. User Mode -Win32
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #include "client.h"
  16. DWORD
  17. TranslateExceptionCode(
  18. DWORD ExceptionCode);
  19. BOOL
  20. SpoolerInit(
  21. VOID)
  22. /*++
  23. Routine Description:
  24. Arguments:
  25. Return Value:
  26. --*/
  27. {
  28. WCHAR szDefaultPrinter[MAX_PATH * 2];
  29. HKEY hKeyPrinters;
  30. DWORD ReturnValue;
  31. //
  32. // Preserve the old device= string in case we can't initialize and
  33. // must defer.
  34. //
  35. if (!RegOpenKeyEx(HKEY_CURRENT_USER,
  36. szPrinters,
  37. 0,
  38. KEY_WRITE|KEY_READ,
  39. &hKeyPrinters)) {
  40. //
  41. // Attempt to retrieve the current default written out.
  42. //
  43. if (GetProfileString(szWindows,
  44. szDevice,
  45. szNULL,
  46. szDefaultPrinter,
  47. COUNTOF(szDefaultPrinter))) {
  48. //
  49. // If it exists, save it away in case we start later when
  50. // the spooler hasn't started (which means we clear device=)
  51. // and then restart the spooler and login.
  52. //
  53. RegSetValueEx(hKeyPrinters,
  54. szDeviceOld,
  55. 0,
  56. REG_SZ,
  57. (PBYTE)szDefaultPrinter,
  58. (wcslen(szDefaultPrinter)+1) *
  59. sizeof(szDefaultPrinter[0]));
  60. }
  61. RegCloseKey(hKeyPrinters);
  62. }
  63. //
  64. // Clear out [devices] and [printerports] device=
  65. //
  66. WriteProfileString(szDevices, NULL, NULL);
  67. WriteProfileString(szPrinterPorts, NULL, NULL);
  68. WriteProfileString(szWindows, szDevice, NULL);
  69. RpcTryExcept {
  70. if (ReturnValue = RpcSpoolerInit((LPWSTR)szNULL)) {
  71. SetLastError(ReturnValue);
  72. ReturnValue = FALSE;
  73. } else {
  74. ReturnValue = TRUE;
  75. }
  76. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  77. SetLastError(TranslateExceptionCode(RpcExceptionCode()));
  78. ReturnValue = FALSE;
  79. } RpcEndExcept
  80. return ReturnValue;
  81. }