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.

205 lines
5.3 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1997
  3. All rights reserved.
  4. Module Name:
  5. permc.cxx
  6. Abstract:
  7. Per Machine Connections
  8. Author:
  9. Ramanathan Venkatapathy (3/18/97)
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "permc.hxx"
  15. #include "rundll.hxx"
  16. VOID
  17. vAddPerMachineConnection(
  18. IN LPCTSTR pServer,
  19. IN LPCTSTR pPrinterName,
  20. IN LPCTSTR pProvider,
  21. IN BOOL bQuiet
  22. )
  23. /*++
  24. Function Description: This function calls AddPerMachineConnection API. If the call fails
  25. and quiet mode is not set, a message box gives the last error.
  26. Parameters: pServer,pPrinterName,pPrintServer,pProvider - arguments for the
  27. AddPerMachineConnection API call.
  28. bQuiet - flag for quiet mode. This is set if /q option is used.
  29. Return Value: NONE.
  30. --*/
  31. {
  32. LPCTSTR pPrintServer;
  33. LPCTSTR pPrinter;
  34. TCHAR szScratch[kPrinterBufMax];
  35. //
  36. // Split the printer name into its components.
  37. //
  38. vPrinterSplitFullName( szScratch, pPrinterName, &pPrintServer, &pPrinter );
  39. if (!AddPerMachineConnection(pServer,pPrinterName,pPrintServer,pProvider)
  40. && !bQuiet) {
  41. iMessage( NULL,
  42. IDS_RUNDLL_TITLE,
  43. IDS_ERR_ADD_MACHINE_CONNECTION,
  44. MB_OK|MB_ICONSTOP|MB_SETFOREGROUND,
  45. kMsgGetLastError,
  46. NULL );
  47. }
  48. }
  49. VOID
  50. vDeletePerMachineConnection(
  51. IN LPCTSTR pServer,
  52. IN LPCTSTR pPrinterName,
  53. IN BOOL bQuiet
  54. )
  55. /*++
  56. Function Description: This function calls DeletePerMachineConnection API. If the call fails
  57. and quiet mode is not set, a message box gives the last error.
  58. Parameters: pServer,pPrinterName - arguments for the DeletePerMachineConnection API call.
  59. bQuiet - flag for quiet mode. This is set if /q option is used.
  60. Return Value: NONE.
  61. --*/
  62. {
  63. if (!DeletePerMachineConnection(pServer,pPrinterName)
  64. && !bQuiet) {
  65. iMessage( NULL,
  66. IDS_RUNDLL_TITLE,
  67. IDS_ERR_DELETE_MACHINE_CONNECTION,
  68. MB_OK|MB_ICONSTOP|MB_SETFOREGROUND,
  69. kMsgGetLastError,
  70. NULL );
  71. }
  72. }
  73. VOID
  74. vEnumPerMachineConnections(
  75. IN LPCTSTR pServer,
  76. IN LPCTSTR pszFileName,
  77. IN BOOL bQuiet
  78. )
  79. /*++
  80. Function Description: This function calls the EnumPerMachineConnection API to enumerate
  81. the per machine printer connections at pServer.
  82. Parameters: pServer - pointer to the name of the machine on which the per machine connections
  83. are to be enumerated.
  84. pszFileName - pointer to the file name where the connection data is to be dumped.
  85. If it is NULL or szNULL, the data is displayed in a EditBox.
  86. bQuiet - flag indicating quiet mode. It is set by using the /q option.
  87. Return Values: NONE.
  88. --*/
  89. {
  90. DWORD cbBuf = 0;
  91. DWORD cbNeeded;
  92. DWORD cReturned;
  93. DWORD dwWritten;
  94. PPRINTER_INFO_4 pPrinterEnum=NULL;
  95. DWORD index;
  96. TStatusB bStatus;
  97. HANDLE hOutputFile = NULL;
  98. TCHAR szNewLine[] = TEXT("\r\n");
  99. bStatus DBGNOCHK = TRUE;
  100. TRunDllDisplay PrEnum(NULL, pszFileName,
  101. (pszFileName && *pszFileName) ? TRunDllDisplay::kFile
  102. : TRunDllDisplay::kEditBox);
  103. bStatus DBGCHK = VALID_OBJ( PrEnum );
  104. if (bStatus) {
  105. if (!(pszFileName && *pszFileName)) {
  106. TString strTemp;
  107. if (bStatus DBGCHK = strTemp.bLoadString( ghInst, IDS_ERR_RUNDLL_MACHINE_CONNECTION )) {
  108. bStatus DBGCHK = PrEnum.SetTitle( strTemp );
  109. }
  110. }
  111. }
  112. if (bStatus) {
  113. cbBuf = 1000;
  114. if (!(pPrinterEnum = (PPRINTER_INFO_4) AllocMem(cbBuf))) {
  115. bStatus DBGCHK = FALSE;
  116. }
  117. }
  118. if (bStatus) {
  119. while (!(bStatus DBGCHK = EnumPerMachineConnections(pServer,(LPBYTE)pPrinterEnum,cbBuf,
  120. &cbNeeded,&cReturned)) &&
  121. (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
  122. FreeMem(pPrinterEnum);
  123. if (!(pPrinterEnum = (PPRINTER_INFO_4) AllocMem(cbNeeded))) {
  124. bStatus DBGCHK = FALSE;
  125. break;
  126. }
  127. cbBuf = cbNeeded;
  128. }
  129. }
  130. if (bStatus) {
  131. for (index=0;cReturned;cReturned--,index++) {
  132. if (!PrEnum.WriteOut(TEXT("Printer Name: ")) ||
  133. !PrEnum.WriteOut(pPrinterEnum[index].pPrinterName) ||
  134. !PrEnum.WriteOut(szNewLine) ||
  135. !PrEnum.WriteOut(TEXT("Server Name: ")) ||
  136. !PrEnum.WriteOut(pPrinterEnum[index].pServerName) ||
  137. !PrEnum.WriteOut(szNewLine) ||
  138. !PrEnum.WriteOut(szNewLine)) {
  139. bStatus DBGCHK = FALSE;
  140. break;
  141. }
  142. }
  143. }
  144. if (bStatus) {
  145. PrEnum.bDoModal();
  146. }
  147. if (pPrinterEnum) {
  148. FreeMem(pPrinterEnum);
  149. }
  150. if (!bStatus && !bQuiet) {
  151. iMessage( NULL,
  152. IDS_RUNDLL_TITLE,
  153. IDS_ERR_ENUM_MACHINE_CONNECTION,
  154. MB_OK|MB_ICONSTOP|MB_SETFOREGROUND,
  155. GetLastError() != ERROR_SUCCESS ? kMsgGetLastError : kMsgNone,
  156. NULL );
  157. }
  158. return;
  159. }