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.

132 lines
4.0 KiB

  1. #include <windows.h>
  2. #include <winspool.h>
  3. #include <stdio.h>
  4. #include <tchar.h>
  5. BYTE Buffer[4096*4];
  6. int _cdecl
  7. wmain(
  8. int argc,
  9. WCHAR *argv[]
  10. )
  11. {
  12. DWORD cb;
  13. DWORD cnt;
  14. DWORD i;
  15. PPRINTER_INFO_1 PrinterInfo = (PPRINTER_INFO_1) Buffer;
  16. PDRIVER_INFO_2 DriverInfo = (PDRIVER_INFO_2) Buffer;
  17. PPRINTPROCESSOR_INFO_1 ProcessorInfo = (PPRINTPROCESSOR_INFO_1) Buffer;
  18. PMONITOR_INFO_2 MonitorInfo = (PMONITOR_INFO_2) Buffer;
  19. PPORT_INFO_2 PortInfo = (PPORT_INFO_2) Buffer;
  20. if (argc >= 3) {
  21. if (argv[1][0] == L'-' && argv[1][1] == L'd' && argv[1][2] == L'd') {
  22. if (!DeletePrinterDriver( NULL, NULL, argv[2] )) {
  23. _tprintf( TEXT("DeletePrinterDriver() failed, ec=%d\n"), GetLastError() );
  24. }
  25. return 0;
  26. }
  27. if (argv[1][0] == L'-' && argv[1][1] == L'd' && argv[1][2] == L'p') {
  28. HANDLE hPrinter;
  29. PRINTER_DEFAULTS PrinterDefaults;
  30. PrinterDefaults.pDatatype = NULL;
  31. PrinterDefaults.pDevMode = NULL;
  32. PrinterDefaults.DesiredAccess = PRINTER_ALL_ACCESS;
  33. OpenPrinter( argv[2], &hPrinter, &PrinterDefaults );
  34. DeletePrinter( hPrinter );
  35. ClosePrinter( hPrinter );
  36. return 0;
  37. }
  38. if (argv[1][0] == L'-' && argv[1][1] == L'd' && argv[1][2] == L'c') {
  39. DeletePrinterConnection( argv[2] );
  40. Sleep(3000);
  41. return 0;
  42. }
  43. if (argv[1][0] == L'-' && argv[1][1] == L'd' && argv[1][2] == L'm') {
  44. DeleteMonitor( NULL, NULL, argv[2] );
  45. return 0;
  46. }
  47. if (argv[1][0] == L'-' && argv[1][1] == L'a' && argv[1][2] == L'm') {
  48. MONITOR_INFO_2 MonitorInfo;
  49. MonitorInfo.pName = argv[2];
  50. MonitorInfo.pEnvironment = NULL;
  51. MonitorInfo.pDLLName = argv[3];
  52. AddMonitor( NULL, 2, (LPBYTE) &MonitorInfo );
  53. return 0;
  54. }
  55. }
  56. if (!EnumPrinters( PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 1, Buffer, sizeof(Buffer), &cb, &cnt )) {
  57. _tprintf( TEXT("EnumPrinters() failed, ec=0x%08x\n"), GetLastError() );
  58. return -1;
  59. }
  60. if (cnt) {
  61. _tprintf( TEXT("\nPrinters:\n") );
  62. for (i=0; i<cnt; i++) {
  63. _tprintf( TEXT(" %s\n"), PrinterInfo[i].pName );
  64. }
  65. }
  66. if (!EnumPrintProcessors( NULL, NULL, 1, Buffer, sizeof(Buffer), &cb, &cnt )) {
  67. _tprintf( TEXT("EnumPrintProcessors() failed, ec=0x%08x\n"), GetLastError() );
  68. return -1;
  69. }
  70. if (cnt) {
  71. _tprintf( TEXT("\nPrint Processors:\n") );
  72. for (i=0; i<cnt; i++) {
  73. _tprintf( TEXT(" %s\n"), ProcessorInfo[i].pName );
  74. }
  75. }
  76. if (!EnumPrinterDrivers( NULL, NULL, 2, Buffer, sizeof(Buffer), &cb, &cnt )) {
  77. _tprintf( TEXT("EnumPrinterDrivers() failed, ec=0x%08x\n"), GetLastError() );
  78. return -1;
  79. }
  80. if (cnt) {
  81. _tprintf( TEXT("\nDrivers:\n") );
  82. for (i=0; i<cnt; i++) {
  83. _tprintf( TEXT(" %s\n"), DriverInfo[i].pName );
  84. _tprintf( TEXT(" Files: %s\n %s\n %s\n"),
  85. DriverInfo[i].pDriverPath,
  86. DriverInfo[i].pDataFile,
  87. DriverInfo[i].pConfigFile
  88. );
  89. }
  90. }
  91. if (!EnumMonitors( NULL, 2, Buffer, sizeof(Buffer), &cb, &cnt )) {
  92. _tprintf( TEXT("EnumMonitors() failed, ec=0x%08x\n"), GetLastError() );
  93. return -1;
  94. }
  95. if (cnt) {
  96. _tprintf( TEXT("\nMonitors:\n") );
  97. for (i=0; i<cnt; i++) {
  98. _tprintf( TEXT(" %s\n"), MonitorInfo[i].pName );
  99. _tprintf( TEXT(" Files: %s\n"), MonitorInfo[i].pDLLName );
  100. }
  101. }
  102. if (!EnumPorts( NULL, 2, Buffer, sizeof(Buffer), &cb, &cnt )) {
  103. _tprintf( TEXT("EnumPorts() failed, ec=0x%08x\n"), GetLastError() );
  104. return -1;
  105. }
  106. if (cnt) {
  107. _tprintf( TEXT("\nPorts:\n") );
  108. for (i=0; i<cnt; i++) {
  109. _tprintf( TEXT(" %s\n"), PortInfo[i].pPortName );
  110. }
  111. }
  112. return 0;
  113. }