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.

206 lines
4.9 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. /*++
  4. Copyright (c) 1990 Microsoft Corporation
  5. Module Name:
  6. printer.c
  7. Abstract:
  8. Printer module for Win32 PDK Setup.
  9. This module has no external dependencies and is not statically linked
  10. to any part of Setup.
  11. Author:
  12. Sunil Pai (sunilp) March 1992
  13. --*/
  14. //
  15. // Get Windows system printer directory
  16. //
  17. CB
  18. GetPrinterDriverDir(
  19. IN RGSZ Args,
  20. IN USHORT cArgs,
  21. OUT SZ ReturnBuffer,
  22. IN CB cbReturnBuffer
  23. )
  24. {
  25. DWORD cbRet = 0;
  26. SZ szServerName = NULL ;
  27. SZ szEnvironment = NULL ;
  28. Unused(Args);
  29. Unused(cArgs);
  30. if ( (cArgs >= 2) ) {
  31. if (*(Args[0]) != '\0') {
  32. szServerName = Args[0];
  33. }
  34. if (*(Args[1]) != '\0') {
  35. szEnvironment = Args[1];
  36. }
  37. }
  38. GetPrinterDriverDirectory(
  39. szServerName, // pName
  40. szEnvironment, // pEnvironment
  41. 1, // Level
  42. ReturnBuffer, // pDriverDirectory
  43. cbReturnBuffer, // cbBuf
  44. &cbRet // pcbNeeded
  45. );
  46. if ( cbRet == 0 ) {
  47. ReturnBuffer[0] = '\0';
  48. }
  49. return lstrlen(ReturnBuffer)+1;
  50. }
  51. BOOL
  52. AddPrinterDriverWorker(
  53. IN LPSTR Model,
  54. IN LPSTR Environment,
  55. IN LPSTR Driver,
  56. IN LPSTR DataFile,
  57. IN LPSTR ConfigFile,
  58. IN LPSTR Server
  59. )
  60. {
  61. DRIVER_INFO_2 DriverInfo2;
  62. ZeroMemory( &DriverInfo2, sizeof(DRIVER_INFO_2) );
  63. DriverInfo2.cVersion = 0;
  64. DriverInfo2.pName = Model; // QMS 810
  65. DriverInfo2.pEnvironment = Environment; // W32x86
  66. DriverInfo2.pDriverPath = Driver; // c:\drivers\pscript.dll
  67. DriverInfo2.pDataFile = DataFile; // c:\drivers\QMS810.PPD
  68. DriverInfo2.pConfigFile = ConfigFile; // c:\drivers\PSCRPTUI.DLL
  69. if(AddPrinterDriver(Server, 2, (LPBYTE)&DriverInfo2)) {
  70. SetReturnText( "ADDED" );
  71. } else {
  72. switch(GetLastError()) {
  73. case ERROR_PRINTER_DRIVER_ALREADY_INSTALLED:
  74. SetReturnText( "PRESENT" );
  75. break;
  76. case ERROR_ACCESS_DENIED:
  77. SetReturnText( "DENIED" );
  78. break;
  79. default:
  80. SetReturnText( "ERROR" );
  81. break;
  82. }
  83. }
  84. return (TRUE);
  85. }
  86. BOOL
  87. AddPrinterWorker(
  88. IN LPSTR Name,
  89. IN LPSTR Port,
  90. IN LPSTR Model,
  91. IN LPSTR Description,
  92. IN LPSTR PrintProcessor,
  93. IN DWORD Attributes,
  94. IN LPSTR Server
  95. )
  96. {
  97. PRINTER_INFO_2 PrinterInfo2;
  98. HANDLE bStatus;
  99. ZeroMemory( &PrinterInfo2, sizeof(PRINTER_INFO_2) );
  100. PrinterInfo2.pServerName = NULL;
  101. PrinterInfo2.pPrinterName = Name;
  102. PrinterInfo2.pShareName = NULL;
  103. PrinterInfo2.pPortName = Port;
  104. PrinterInfo2.pDriverName = Model;
  105. PrinterInfo2.pComment = Description;
  106. PrinterInfo2.pLocation = NULL;
  107. PrinterInfo2.pDevMode = (LPDEVMODE)NULL;
  108. PrinterInfo2.pSepFile = NULL;
  109. PrinterInfo2.pPrintProcessor = PrintProcessor;
  110. PrinterInfo2.pDatatype = NULL;
  111. PrinterInfo2.pParameters = NULL;
  112. PrinterInfo2.Attributes = Attributes;
  113. PrinterInfo2.Priority = 0;
  114. PrinterInfo2.DefaultPriority = 0;
  115. PrinterInfo2.StartTime = 0;
  116. PrinterInfo2.UntilTime = 0;
  117. PrinterInfo2.Status = 0;
  118. PrinterInfo2.cJobs = 0;
  119. PrinterInfo2.AveragePPM = 0;
  120. bStatus = AddPrinter( Server, 2, (LPBYTE)&PrinterInfo2);
  121. if ( bStatus != (HANDLE)NULL ) {
  122. SetReturnText( "ADDED" );
  123. ClosePrinter(bStatus);
  124. return( TRUE );
  125. }
  126. else {
  127. switch(GetLastError()) {
  128. case ERROR_PRINTER_ALREADY_EXISTS:
  129. SetReturnText( "PRESENT" );
  130. break;
  131. #if 0
  132. case ERROR_ACCESS_DENIED:
  133. SetReturnText( "DENIED" );
  134. break;
  135. #endif
  136. default:
  137. SetReturnText( "ERROR" );
  138. break;
  139. }
  140. return( TRUE );
  141. }
  142. }
  143. BOOL
  144. AddPrinterMonitorWorker(
  145. IN LPSTR Model,
  146. IN LPSTR Environment,
  147. IN LPSTR Driver,
  148. IN LPSTR Server
  149. )
  150. {
  151. MONITOR_INFO_2 MonitorInfo2;
  152. ZeroMemory( &MonitorInfo2, sizeof(MONITOR_INFO_2) );
  153. MonitorInfo2.pName = Model; // Local Port
  154. MonitorInfo2.pEnvironment = Environment; // W32x86
  155. MonitorInfo2.pDLLName = Driver; // c:\winnt\system32\localmon.dll
  156. if(AddMonitor(Server, 2, (LPBYTE)&MonitorInfo2)) {
  157. SetReturnText( "ADDED" );
  158. } else {
  159. switch(GetLastError()) {
  160. case ERROR_ALREADY_EXISTS:
  161. SetReturnText( "PRESENT" );
  162. break;
  163. case ERROR_ACCESS_DENIED:
  164. SetReturnText( "DENIED" );
  165. break;
  166. default:
  167. SetReturnText( "ERROR" );
  168. break;
  169. }
  170. }
  171. return (TRUE);
  172. }