Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Printers, thinPrint, and Autoit

$
0
0

I am working on a script that will add printers, ports, enable printer pooling, and assign multiple ports to a printer. The catch to this is that thinPrint is being used to manage the printers. If I add the printer ports as a local port in the registry, thinPrint will not pick it up....however, if I add the printer without the local ports, the printer will not install. Does anybody have any experience automating thinPrint?....or installing printers on NOT a local port?

Here is my code so far...

AutoIt         
  1. #include <GuiConstants.au3>
  2. #include <buttonconstants.au3>
  3. #include <windowsconstants.au3>
  4. #include <StaticConstants.au3>
  5. #include <Constants.au3>
  6. #include <GUIConstantsEx.au3>
  7. #include <File.au3>
  8. #include <zip.au3>
  9.  
  10. Global $iUser, $user
  11. installPrinters()
  12. Func main()
  13.    
  14.  
  15.     MsgBox(64, "Please Read!", "The first time thinPrint Helper is ran you must create each individual printer and then reboot the Server. After reboot, running thinPrint Helper will install the printers. You're welcome!")
  16.     RunWait(@ComSpec & " /c " & 'CScript C:\Windows\System32\Printing_Admin_Scripts\en-us\prndrvr.vbs -a -m "TP Output Gateway" -i "C:\driver\oemprint.inf"', "", @SW_HIDE)
  17.     GUICreate("thinPrint Helper", 400, 100)
  18.     GUICtrlCreateLabel("Enter Printer Name:", 85, 45)
  19.     $iUser = GUICtrlCreateInput("", 200, 43, 100, 20)
  20.     $bCreate = GUICtrlCreateButton("Create!", 150, 68, 100, 30)
  21.     GUISetState()
  22.  
  23.  
  24.     While 1
  25.         $msg = GUIGetMsg()
  26.         Select
  27.             Case $msg = $GUI_EVENT_CLOSE
  28.                 ExitLoop
  29.             Case $msg = $bCreate
  30.                 Call(createPrinters())
  31.         EndSelect
  32.     WEnd
  33. EndFunc   ;==>main
  34.  
  35. Func createPrinters()
  36.     $user = GUICtrlRead($iUser)
  37.     $file = FileOpen(@DesktopDir & "\thinkey.reg", 2)
  38.     FileWrite($file, "Windows Registry Editor Version 5.00" & @CRLF & @CRLF & '[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\ThinPrint Port\' & $user & '-1:]' & @CRLF & '"Protocol"=dword:00000002' & @CRLF & '"NetSend"=dword:00000001' & @CRLF & '"WTSMsgBox"=dword:00000001' & @CRLF & '"CompressData"=dword:00000000' & @CRLF & '"PackagesAccess"=dword:00000001' & @CRLF & '"SendPackages"=dword:00000001' & @CRLF & '"PackageSize"=dword:0000fa00' & @CRLF & '"BandwidthAccess"=dword:00000000' & @CRLF & '"Bandwidth"=dword:0003e800' & @CRLF & '"BandwidthCtrlEnabled"=dword:00000000' & @CRLF & '"Port"=dword:00000fa0' & @CRLF & '"Filter"="l"' & @CRLF & '"PrinterQueueName"=""' & @CRLF & '"TPACScheme"="%N#%U:%I"' & @CRLF & '"FormatString"="%*[^#]#%[^:]:%s"' & @CRLF & '"IsVCGPort"=dword:00000000' & @CRLF & '"IsCSvcPort"=dword:00000000' & @CRLF & '"LogJobStatistic"=dword:00000000' & @CRLF & '"RefreshTimeJobStat"=dword:000003e8' & @CRLF & '"CLevel"=dword:00000005'&@CRLF)
  39.     FileWrite($file, '[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\ThinPrint Port\' & $user & '-2:]' & @CRLF & '"Protocol"=dword:00000002' & @CRLF & '"NetSend"=dword:00000001' & @CRLF & '"WTSMsgBox"=dword:00000001' & @CRLF & '"CompressData"=dword:00000000' & @CRLF & '"PackagesAccess"=dword:00000001' & @CRLF & '"SendPackages"=dword:00000001' & @CRLF & '"PackageSize"=dword:0000fa00' & @CRLF & '"BandwidthAccess"=dword:00000000' & @CRLF & '"Bandwidth"=dword:0003e800' & @CRLF & '"BandwidthCtrlEnabled"=dword:00000000' & @CRLF & '"Port"=dword:00000fa0' & @CRLF & '"Filter"="l"' & @CRLF & '"PrinterQueueName"=""' & @CRLF & '"TPACScheme"="%N#%U:%I"' & @CRLF & '"FormatString"="%*[^#]#%[^:]:%s"' & @CRLF & '"IsVCGPort"=dword:00000000' & @CRLF & '"IsCSvcPort"=dword:00000000' & @CRLF & '"LogJobStatistic"=dword:00000000' & @CRLF & '"RefreshTimeJobStat"=dword:000003e8' & @CRLF & '"CLevel"=dword:00000005'&@CRLF)
  40.     FileWrite($file, '[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\ThinPrint Port\' & $user & '-3:]' & @CRLF & '"Protocol"=dword:00000002' & @CRLF & '"NetSend"=dword:00000001' & @CRLF & '"WTSMsgBox"=dword:00000001' & @CRLF & '"CompressData"=dword:00000000' & @CRLF & '"PackagesAccess"=dword:00000001' & @CRLF & '"SendPackages"=dword:00000001' & @CRLF & '"PackageSize"=dword:0000fa00' & @CRLF & '"BandwidthAccess"=dword:00000000' & @CRLF & '"Bandwidth"=dword:0003e800' & @CRLF & '"BandwidthCtrlEnabled"=dword:00000000' & @CRLF & '"Port"=dword:00000fa0' & @CRLF & '"Filter"="l"' & @CRLF & '"PrinterQueueName"=""' & @CRLF & '"TPACScheme"="%N#%U:%I"' & @CRLF & '"FormatString"="%*[^#]#%[^:]:%s"' & @CRLF & '"IsVCGPort"=dword:00000000' & @CRLF & '"IsCSvcPort"=dword:00000000' & @CRLF & '"LogJobStatistic"=dword:00000000' & @CRLF & '"RefreshTimeJobStat"=dword:000003e8' & @CRLF & '"CLevel"=dword:00000005'&@CRLF)
  41.     FileWrite($file, '[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports]' &@CRLF&'"'&$user&'-1:"=""'&@CRLF)
  42.     FileWrite($file, '[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports]' &@CRLF&'"'&$user&'-2:"=""'&@CRLF)
  43.     FileWrite($file, '[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports]' &@CRLF&'"'&$user&'-3:"=""'&@CRLF)
  44.     FileClose($file)
  45.     RunWait(@ComSpec & " /c " & 'regedit.exe /s ' & @DesktopDir & "\thinkey.reg", "", @SW_HIDE)
  46.     FileDelete($file)
  47.     $printerfile = FileOpen(@DesktopDir & "\printerlist.txt", 1)
  48.     FileWriteLine($printerfile, $user & @CRLF)
  49.     FileClose($printerfile)
  50.     GUICtrlSetData($iUser,"")
  51. EndFunc   ;==>createPrinters
  52.  
  53. Func installPrinters()
  54.     $filePath = @DesktopDir & "\printerlist.txt"
  55.     If FileExists($filePath) Then
  56.         $totalLines = _FileCountLines($filePath)
  57.         $count = 1
  58.         Do
  59.             $file = FileOpen(@DesktopDir & "\printerlist.txt", 0)
  60.             $printName = FileReadLine($file, $count)
  61.             RunWait(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /if /b "_#' & $printName & '" /f "C:\driver\oemprint.inf" /r "' & $printName & '-1:" /m "TP Output Gateway', "", @SW_HIDE)
  62.             RunWait(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /Xs /n "_#' & $printName & '" Portname "' & $printName & '-1:,' & $printName & '-2:,' & $printName & '-3:"', "", @SW_HIDE)
  63.             $count = $count + 1
  64.         Until $count = $totalLines + 1
  65.         MsgBox(64,"All done!","Printers have been installed!")
  66.         FileDelete($filePath)
  67.     Else
  68.         Call(main())
  69.     EndIf
  70. EndFunc   ;==>installPrinters

Any help is appreciated.

Thanks!


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>