| 
| 
| 
| #201646 - 2011-02-24 11:38 AM  Re: Printer Dialog
[Re:  ShaneEP] |  
| BradV   Seasoned Scripter
 
      
 Registered:  2006-08-16
 Posts: 687
 Loc:  Maryland, USA
 | 
Not sure, but this might give a clue:
 vb.net example
 
 or:
 
 vb example
 |  
| Top |  |  |  |  
| 
| 
| #201658 - 2011-02-26 03:11 AM  Re: Printer Dialog
[Re:  Allen] |  
| NTDOC   Administrator
 
       
   Registered:  2000-07-28
 Posts: 11627
 Loc:  CA
 | 
Found this but have not played with any of it.http://www.scriptingtraining.com/forum2/forum_posts.asp?TID=3840
 
 The link to Rob's site does mention this as well
 
 C:\Windows\System32
 prncnfg.vbs
 prndrvr.vbs
 prnjobs.vbs
 prnmngr.vbs
 prnport.vbs
 prnqctl.vbs
 pubprn.vbs
 
 
 |  
| Top |  |  |  |  
| 
| 
| #201661 - 2011-02-26 11:28 PM  Re: Printer Dialog
[Re:  NTDOC] |  
| ShaneEP   MM club member
 
       
   Registered:  2002-11-29
 Posts: 2127
 Loc:  Tulsa, OK
 | 
Yeah I've found how to do most of those (via wmi scirptomatic), the only problem is that none of the tools initiate the printer dialog. This is what I have made so far (although Allen has probably already worked out some magical solution). It dynamically creates a list of available printers. I've only been able to test it on WinXP Home SP3 though. So if any of you get it to work on anything else, please let me know.
 
$RC=setoption("NoVarsinstrings","on")
$RC=setoption("NoMacrosinstrings","on")
$System = CreateObject("Kixtart.System")
SelectPrinterForm()
Function SelectPrinterForm()
   $defprinter = Split(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),",")[0]
   $objWMIService = GetObject("winmgmts:\\"+@WkSta+"\root\CIMV2")
   $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL")
   $x=0
   for each $colitem in $colitems
      $x=$x+1
   next
   Global $printers[$x-1]
   $x=0
   for each $colitem in $colitems
      $printers[$x]=$colitem.Name
      $x=$x+1
   next
   $PrinterSelectGroupHeight = (UBound($printers)+1)*30+40
   $PrinterSelectFormHeight = (UBound($printers)+1)*30+170
   $PrinterSelectform = $System.Form()
   $PrinterSelectform.Width = 400
   $PrinterSelectform.Height = $PrinterSelectFormHeight
   $PrinterSelectform.Text = "Print"
   $PrinterSelectTabs = $PrinterSelectForm.Controls.Add("TabControl")
   $PrinterSelectTabs.Height = $PrinterSelectForm.Height-50
   $PrinterSelectTabs.Width = $PrinterSelectForm.Width-20
   $PrinterSelectTabs.Center()
   $PrinterSelectTab = $PrinterSelectTabs.TabPages.Add("General")
   $PrinterSelectGroup = $PrinterSelectTab.Controls.Add("GroupBox")
   $PrinterSelectGroup.Text = "Select Printer"
   $PrinterSelectGroup.Height = $PrinterSelectGroupHeight
   $PrinterSelectGroup.Width = $PrinterSelectTabs.Width-30
   $PrinterSelectGroup.Top = 10
   $PrinterSelectGroup.Left = 10
   $top = 0
   For $x=1 to UBound($printers)+1
      $null = Execute('$printer'+$x+'=$PrinterSelectGroup.Controls.Add("ToolButton")')
      $null = Execute('$printer'+$x+'.Text=$printers[$x-1]')
      $null = Execute('$printer'+$x+'.BackColor="TransParent"')
      $null = Execute('$printer'+$x+'.FlatStyle=0')
      $null = Execute('$printer'+$x+'.BorderStyle=0')
      $null = Execute('$printer'+$x+'.Width=300') 
      $null = Execute('$printer'+$x+'.Height=30')
      $null = Execute('$printer'+$x+'.Cursor=16')
      $null = Execute('$printer'+$x+'.Top=20+$top')
      $null = Execute('$top=$printer'+$x+'.Top+10')
      $null = Execute('$printer'+$x+'.Left=$PrinterSelectGroup.Left+20')
      $null = Execute('$printer'+$x+'.OnClick="SetSelectedPrinter($printer'+$x+')"')
      if $printers[$x-1]=$defprinter
         $null = Execute('$printer'+$x+'.Icon=@ScriptDir+"\printer_def.ico"')
         $null = Execute('$printer'+$x+'.BackColor="silver"')
         $null = Execute('$printer'+$x+'.Pushed=1')
         $null = Execute('$selectedprinter=$printer'+$x)
      else
         $null = Execute('$printer'+$x+'.Icon=@ScriptDir+"\printer.ico"')
      endif
   Next
   $printbutton = $PrinterSelectTab.Controls.Add("ToolButton")
   $printbutton.Text = "Print"
   $printbutton.Top = $PrinterSelectGroup.Bottom+10
   $printbutton.Left = $PrinterSelectGroup.Left+80
   $printbutton.OnClick = "PrintHoursReport()"
   $printCancelbutton = $PrinterSelectTab.Controls.Add("ToolButton")
   $printCancelbutton.Text = "Cancel"
   $printCancelbutton.Top = $PrinterSelectGroup.Bottom+10
   $printCancelbutton.Left = $PrinterSelectGroup.Right-80-$printCancelbutton.Width
   $printCancelbutton.OnClick = "$$PrinterSelectform.Hide()"
   $PrinterSelectform.Center()
   $PrinterSelectform.Show()
   While $PrinterSelectform.Visible
      $Nul = Execute($PrinterSelectform.DoEvents)
   Loop
   Exit 0
EndFunction
Function SetSelectedPrinter($p)
   For $x=1 to UBound($printers)+1
      $null = Execute('$printer'+$x+'.BackColor=""')
   Next
   $selectedprinter = $p
   $selectedPrinter.BackColor = "silver"
EndFunction
Function PrintHoursReport()
   $testfile = @ScriptDir+"\test-print-file.txt"
   if not exist($testfile)
      $testfh = FreeFileHandle()
      $null = Open($testfh,$testfile,5)
      $null = WriteLine($testfh,"This is simply a test of the print form.")
      $null = Close($testfh)
   endif
   $prntr = $selectedprinter.text
   $null = SetDefaultPrinter($prntr)
   Sleep 1
   $objShellApp = CreateObject("Shell.Application")
   $objShellApp.ShellExecute($testfile,"","","print",0)
   Sleep 1
   $null = SetDefaultPrinter($defprinter)
   $PrinterSelectform.Hide()
EndFunction
Also...The .ico files are just little printer icons. Not sure how to upload them on here. But are any of you keen on how to place a windows icon in the form so there isnt the dependency on the .ico files?
 
 Edited by CitrixMan (2011-02-26 11:39 PM)
 |  
| Top |  |  |  |  
| 
| 
| #201662 - 2011-02-27 04:33 AM  Re: Printer Dialog
[Re:  ShaneEP] |  
| NTDOC   Administrator
 
       
   Registered:  2000-07-28
 Posts: 11627
 Loc:  CA
 | 
I've not played with KiXform in years but as I recall you can use base64.exe to create a text hash I think.
 I'm sure one of the others that either continues to use it or was using it much more than I did can help you with it.
 
 Who knows... maybe the author old Shawn the SheepShagger may stop by and help out
   |  
| Top |  |  |  |  
| 
| 
| #201663 - 2011-02-28 11:52 AM  Re: Printer Dialog
[Re:  NTDOC] |  
| BradV   Seasoned Scripter
 
      
 Registered:  2006-08-16
 Posts: 687
 Loc:  Maryland, USA
 | 
Shane, do you need the printer dialog window, or just want to print?  This link shows some extensive methods to use WSH to print:
 Printing Documents in WSH
 
 Regards,
 
 Brad
 |  
| Top |  |  |  |  
| 
| 
| #201667 - 2011-02-28 07:27 PM  Re: Printer Dialog
[Re:  BradV] |  
| ShaneEP   MM club member
 
       
   Registered:  2002-11-29
 Posts: 2127
 Loc:  Tulsa, OK
 | 
Ah thanks Brad! That article led me down a path that I think may just work. Check this out...
 
Function IEPrintDialog($printdoc,optional $dialog)
   if $dialog<>1
      $dialog=2
   endif
   $objIE = CreateObject("InternetExplorer.Application")
   if @error=0
      $objIE.Visible = 0
      $objIE.Navigate($printdoc)
      Do
         Sleep 0.1
      Until $objIE.ReadyState = 4
      if $objIE.QueryStatusWB(6) >= 3
         $objIE.ExecWB(6,$dialog,2,0)
;         Do
;            Sleep 0.1
;         Until $objIE.PrintTemplateTeardown(pDisp)=1
         sleep 5
         $objIE.Quit
      else
         $objIE.Quit
         exit 1
      endif
   else
      exit @Error
   endif
   exit 0
EndFunction
The only problem Im having is having to sleep so enough time is allowed for the job to be sent before destroying the $ieobj. The article describes a way to check for the PrintTemplateTeardown event that signals the end of the print process, but I have no idea how to check an event of an object in kix. Maybe one of you knows vbs well enough to convert the syntax?
 
 http://www.aspfree.com/c/a/Windows-Scripting/Printing-Documents-in-WSH/5/
 http://msdn.microsoft.com/en-us/library/aa768346%28v=VS.85%29.aspx
 |  
| Top |  |  |  |  
| 
| 
| #201671 - 2011-03-01 05:44 AM  Re: Printer Dialog
[Re:  ShaneEP] |  
| Allen   KiX Supporter
 
       
 Registered:  2003-04-19
 Posts: 4562
 Loc:  USA
 | 
Okay... try this.
 
 
function IEPrint($document,optional $mode)
  dim $OLECMDID_PRINT, $OLECMDEXECOPT, $IE, $rc, $sc
  $OLECMDID_PRINT=6
  if $mode
    $OLECMDEXECOPT=1
  else
    $OLECMDEXECOPT=2
  endif
  if exist($document)
    $ie = createobject("internetexplorer.application")
    $ie.navigate ($document)
    While $IE.Busy and $IE.ReadyState <> 4 sleep 0.2 loop
    While $IE.Document.readystate <> "complete" Loop
    $IE.visible=0
    $sc = CreateObject("ScriptControl")
    $sc.language = "VBScript"
    $sc.timeout = 300000
    $sc.addobject('vbIE',$IE)
    $sc.addcode('vbIE.ExecWB ' + $OLECMDID_PRINT + ',' + $OLECMDEXECOPT + ',2,0')
    $sc.run
    $ie.quit
  else
    exit 2
  endif
endfunction
 Last week when I initially was trying this, I was using very similar code as yours but the dialog would show up and then quickly disappear.  This did not happen under vbscript.  I ran out of time and never could figure out what was causing it until tonight.  If the visibility setting is on the dialog box would just disappear under kix.
 
 Then I started messing with the delay, and read that when the 3rd option is set to 2 like you have it, it is supposed to halt, but in kix it does not.  However in vbscript it does, thus the code above.
 
 Anyone have any idea why kix is handling these events differently than vbscript?
 
 |  
| Top |  |  |  |  
| 
| 
| #201672 - 2011-03-01 12:53 PM  Re: Printer Dialog
[Re:  Allen] |  
| BradV   Seasoned Scripter
 
      
 Registered:  2006-08-16
 Posts: 687
 Loc:  Maryland, USA
 | 
Hi Allen,
 When I tried your script, I got a dialog box asking if I wanted to open, save, or cancel.  I selected open, but never got any printing.
 
 I tried the notepad print in the reference URL and it worked as follows:
 
 
 Function NotepadPrint($objDocument)
   $objDocument.InvokeVerb("Print")
EndFunction
;
Function Get_Doc_Obj($strFolder, $strDocument)
   Dim $objShell, $objFolder, $colItems, $objItem
   $objShell  = CreateObject("Shell.Application")
   $objFolder = $objShell.NameSpace($strFolder)
   $colItems  = $objFolder.Items
   ;
   For Each $objItem In $colItems
      If $objItem = $strDocument
         $Get_Doc_Obj = $objItem
         Return
      EndIf
   Next
EndFunction
 The above was in functions.kix
 
 
 Include "functions.kix"
Dim $strUser, $strFile, $rc, $strFolder, $objDocument
$strUser   = @USERID
$strFolder = "C:\Documents and Settings\" + $struser + "\Desktop\"
$strFile   = $strUser + "_info.ini"
;
$objDocument = Get_Doc_Obj($strFolder, $strFile)
$rc          = NotepadPrint($objDocument)
 It briefly displayed the notepad as it printed.  I'll have to keep looking.
 |  
| Top |  |  |  |  
| 
| 
| #201676 - 2011-03-01 05:19 PM  Re: Printer Dialog
[Re:  ShaneEP] |  
| ShaneEP   MM club member
 
       
   Registered:  2002-11-29
 Posts: 2127
 Loc:  Tulsa, OK
 | 
The dialog on my function above stays open fine as well...if I have that sleep in there. if not the ie object gets destroyed before the print job is completely sent. the problem seems to lie in finding a way to loop and check for the completion of the print before destroying the object and terminating script.
 In the vb example they do this...
 
 Set objIE = WScript.CreateObject("InternetExplorer.Application", "IE_")
...rest of printing stuff here...
Do While Not blnPrintingComplete
   WScript.Sleep 50
Loopand
 
 Sub IE_PrintTemplateTeardown(pDisp)
   WScript.Sleep 200
   blnPrintingComplete = True
End SubIs there not a way to create the object and use it to watch for events like PrintTemplateTeardown in kix?
 |  
| Top |  |  |  |  
 Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
 
 | 
| 
 
| 0 registered
and 739 anonymous users online. 
 | 
 |  |