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.
 Code:
$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)