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.

107 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. WCHAR szDefaultPrinter[MAX_PATH * 2];
  24. HKEY hKeyPrinters;
  25. DWORD ReturnValue;
  26. //
  27. // Preserve the old device= string in case we can't initialize and
  28. // must defer.
  29. //
  30. if (!RegOpenKeyEx(HKEY_CURRENT_USER,
  31. szPrinters,
  32. 0,
  33. KEY_WRITE|KEY_READ,
  34. &hKeyPrinters)) {
  35. //
  36. // Attempt to retrieve the current default written out.
  37. //
  38. if (GetProfileString(szWindows,
  39. szDevice,
  40. szNULL,
  41. szDefaultPrinter,
  42. COUNTOF(szDefaultPrinter))) {
  43. //
  44. // If it exists, save it away in case we start later when
  45. // the spooler hasn't started (which means we clear device=)
  46. // and then restart the spooler and login.
  47. //
  48. RegSetValueEx(hKeyPrinters,
  49. szDeviceOld,
  50. 0,
  51. REG_SZ,
  52. (PBYTE)szDefaultPrinter,
  53. (wcslen(szDefaultPrinter)+1) *
  54. sizeof(szDefaultPrinter[0]));
  55. }
  56. RegCloseKey(hKeyPrinters);
  57. }
  58. //
  59. // Clear out [devices] and [printerports] device=
  60. //
  61. WriteProfileString(szDevices, NULL, NULL);
  62. WriteProfileString(szPrinterPorts, NULL, NULL);
  63. WriteProfileString(szWindows, szDevice, NULL);
  64. RpcTryExcept {
  65. if (ReturnValue = RpcSpoolerInit((LPWSTR)szNULL)) {
  66. SetLastError(ReturnValue);
  67. ReturnValue = FALSE;
  68. } else {
  69. ReturnValue = TRUE;
  70. }
  71. } RpcExcept(I_RpcExceptionFilter(RpcExceptionCode())) {
  72. SetLastError(TranslateExceptionCode(RpcExceptionCode()));
  73. ReturnValue = FALSE;
  74. } RpcEndExcept
  75. return ReturnValue;
  76. }