Sign in to follow this  
Followers 0
allSystemsGo

Printers, thinPrint, and Autoit

1 post in this topic

#1 ·  Posted (edited)

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...

#include <GuiConstants.au3>
#include <buttonconstants.au3>
#include <windowsconstants.au3>
#include <StaticConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <File.au3>
#include <zip.au3>

Global $iUser, $user
installPrinters()
Func main()
    

    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!")
    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)
    GUICreate("thinPrint Helper", 400, 100)
    GUICtrlCreateLabel("Enter Printer Name:", 85, 45)
    $iUser = GUICtrlCreateInput("", 200, 43, 100, 20)
    $bCreate = GUICtrlCreateButton("Create!", 150, 68, 100, 30)
    GUISetState()


    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $bCreate
                Call(createPrinters())
        EndSelect
    WEnd
EndFunc   ;==>main

Func createPrinters()
    $user = GUICtrlRead($iUser)
    $file = FileOpen(@DesktopDir & "\thinkey.reg", 2)
    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)
    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)
    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)
    FileWrite($file, '[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports]' &@CRLF&'"'&$user&'-1:"=""'&@CRLF)
    FileWrite($file, '[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports]' &@CRLF&'"'&$user&'-2:"=""'&@CRLF)
    FileWrite($file, '[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports]' &@CRLF&'"'&$user&'-3:"=""'&@CRLF)
    FileClose($file)
    RunWait(@ComSpec & " /c " & 'regedit.exe /s ' & @DesktopDir & "\thinkey.reg", "", @SW_HIDE)
    FileDelete($file)
    $printerfile = FileOpen(@DesktopDir & "\printerlist.txt", 1)
    FileWriteLine($printerfile, $user & @CRLF)
    FileClose($printerfile)
    GUICtrlSetData($iUser,"")
EndFunc   ;==>createPrinters

Func installPrinters()
    $filePath = @DesktopDir & "\printerlist.txt"
    If FileExists($filePath) Then
        $totalLines = _FileCountLines($filePath)
        $count = 1
        Do
            $file = FileOpen(@DesktopDir & "\printerlist.txt", 0)
            $printName = FileReadLine($file, $count)
            RunWait(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /if /b "_#' & $printName & '" /f "C:\driver\oemprint.inf" /r "' & $printName & '-1:" /m "TP Output Gateway', "", @SW_HIDE)
            RunWait(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /Xs /n "_#' & $printName & '" Portname "' & $printName & '-1:,' & $printName & '-2:,' & $printName & '-3:"', "", @SW_HIDE)
            $count = $count + 1
        Until $count = $totalLines + 1
        MsgBox(64,"All done!","Printers have been installed!")
        FileDelete($filePath)
    Else
        Call(main())
    EndIf
EndFunc   ;==>installPrinters

Any help is appreciated.

Thanks!

Edited by allSystemsGo

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0