Printing in VBscript

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 13 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
epoclaen
Posts: 3
Last visit: Thu May 13, 2010 2:15 am

Printing in VBscript

Post by epoclaen »

I'm trying to create a Windows Scripting or a VBscript macro that will print an image given it's file path and name, preferably without having to go through some image application like MSpaint or Irfanview.

On top of that, I'll want to set the printer settings to what they call "borderless" in the printer's Print Settings and to make sure the paper size is set to 8.5" by 11".

I can grab each printer's Print Settings (kinda, in theory anyway) by using the following .vbs code:

Code: Select all

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!" & strComputer & "rootcimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_PrinterConfiguration")
For Each objPrinter in colInstalledPrinters
  ' Enumerate the properties of the object.
  strResult = ""
  For Each strSetting in objPrinter.Properties_
      ' Display the values of the Name and Value properties of the SWbemProperty object
      If strSetting.Name = "Orientation" Then
        If strSetting.Value = 1 Then
          strResult = strResult & strSetting.Name & " = Portrait" & VbCr
        Else
          strResult = strResult & strSetting.Name & " = Landscape" & VbCr
        End If
      ElseIf strSetting.Name = "TTOption" Then
        If strSetting.Value = 1 Then
          strResult = strResult & strSetting.Name & " = Print TrueType fonts as graphics." & VbCr
        ElseIf strSetting.Value = 2 Then
          strResult = strResult & strSetting.Name & " = Download TrueType fonts as soft fonts." & VbCr
        Else
          strResult = strResult & strSetting.Name & " = Substitute device fonts for TrueType fonts." & VbCr
        End If
      Else
        strResult = strResult & strSetting.Name & " = " & strSetting.Value & VbCr
      End If
  Next
  Wscript.Echo  strResult
Next
I don't see any settings for "borderless" and opening any program's Print Settings dialog box and changing the values doesn't initiate any changes to the output of this script.

Am I way off base here? I can't imagine that this would be that tricky!

Thanks,
Jeff
User avatar
epoclaen
Posts: 3
Last visit: Thu May 13, 2010 2:15 am

Printing in VBscript

Post by epoclaen »

I'm trying to create a Windows Scripting or a VBscript macro that will print an image given it's file path and name, preferably without having to go through some image application like MSpaint or Irfanview.

On top of that, I'll want to set the printer settings to what they call "borderless" in the printer's Print Settings and to make sure the paper size is set to 8.5" by 11".

I can grab each printer's Print Settings (kinda, in theory anyway) by using the following .vbs code:

Code: Select all

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!" & strComputer & "rootcimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_PrinterConfiguration")
For Each objPrinter in colInstalledPrinters
  ' Enumerate the properties of the object.
  strResult = ""
  For Each strSetting in objPrinter.Properties_
      ' Display the values of the Name and Value properties of the SWbemProperty object
      If strSetting.Name = "Orientation" Then
        If strSetting.Value = 1 Then
          strResult = strResult & strSetting.Name & " = Portrait" & VbCr
        Else
          strResult = strResult & strSetting.Name & " = Landscape" & VbCr
        End If
      ElseIf strSetting.Name = "TTOption" Then
        If strSetting.Value = 1 Then
          strResult = strResult & strSetting.Name & " = Print TrueType fonts as graphics." & VbCr
        ElseIf strSetting.Value = 2 Then
          strResult = strResult & strSetting.Name & " = Download TrueType fonts as soft fonts." & VbCr
        Else
          strResult = strResult & strSetting.Name & " = Substitute device fonts for TrueType fonts." & VbCr
        End If
      Else
        strResult = strResult & strSetting.Name & " = " & strSetting.Value & VbCr
      End If
  Next
  Wscript.Echo  strResult
Next
I don't see any settings for "borderless" and opening any program's Print Settings dialog box and changing the values doesn't initiate any changes to the output of this script.

Am I way off base here? I can't imagine that this would be that tricky!

Thanks,
Jeff
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Printing in VBscript

Post by rasimmer »

Some printer setting are driver driven, so you may not be able to access it via WMI. Sometimes vendors will provide an EXE that you can pass CMD line parameters to the printer. The simplest method, assuming you have a network print server and would like the setting set globally, is to just do it at the server level.
User avatar
epoclaen
Posts: 3
Last visit: Thu May 13, 2010 2:15 am

Printing in VBscript

Post by epoclaen »

Some printer setting are driver driven, so you may not be able to access it via WMI.I suspected as much. The interesting thing though is that an unrelated application (Jasc Paint Shop Album) includes their own interface for printer settings that includes the "borderless" option. So somewhere, somehow, their software is able to either access this printer setting or they have their own software-driven print parameters that allows a "borderless" layout.
Sometimes vendors will provide an EXE that you can pass CMD line parameters to the printer.I'll dig through the drivers folder, but I didn't find any documentation for command line parameters for this printer online. It sure would make life easier if there is one though!

The simplest method, assuming you have a network print server and would like the setting set globally, is to just do it at the server level.Yeah, that's not an option for this. These settings are strictly meant for just this one image.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Printing in VBscript

Post by jvierra »

You cannot print images without an imagung program that knows how to print. All rendering is don in an application. Printers only know how to receive a windows bitmap and dump it, raw, to the printer.

The printer settings you can sse through WMI or the driver manager are only the defaults. Each document can establish it's own settings at print time.

Look more deeply into this in the Microsft MSDN library.

There are some tools that can be automated through COM. WOrd, Excel and MIcrosoft Picture Manager can all be automated to set the output settings an drender the image to teh printer. There are also numerous third party tools that can automate this.

To automate printer setups Microsft delivers a set of scripts that are in c:WIndowsSystem32.

prncnfg.vbsprndrvr.vbsprnjobs.vbsprnmngr.vbsprnport.vbsprnqctl.vbs

These are all documented in teh online help system. Some can be used remotely. Nearly all use the -? switch to display help.

Some settings are specific to a particular vendors device. These can only be scripted if the vendor supplies a utility to do so. Most vendors supply this utility.

Global issues like "borderless" can only be set by an application because they really only apply to a single document although the defaults can be changed via the spooler settings.




This topic is 13 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked