How to Print to a Local Printer from the Command Prompt

Here's a way to do it with VBScript. Based on an answer provided by Jobbo.

The catch is, you must have a program registered as the default handler. In other words, if you just type the name of a file from the command line, it should open in the appropriate program. For example, if you pass the argument of "file.pdf" you must have a PDF viewer installed. If you want to print a Word document, you must have Word (I think a viewer should work, but I didn't test that) installed.

One more thing, some programs leave a window open (Adobe Acrobat Reader X) after the document prints. You could add logic to the script to close it, but I'll leave that up to you.

To use, type in cscript /nologo <name_of_script.vbs> <name_of_file_to_print> where <name_of_script.vbs> is the name of the program you save this under, and <name_of_file_to_print> is the name of the file you would like to print. If the path contains spaces, enclose the argument in quotes.

Option Explicit

Dim shl, objFS
Dim fldr
Dim files,file
Dim file_to_print,wrk_folder

Set shl = CreateObject("Shell.Application")
Set objFS = CreateObject("Scripting.FileSystemObject")

if not wscript.Arguments.Count = 1 then 
    wscript.echo "Missing parameter!"
    wscript.quit
end if

file_to_print = wscript.arguments(0)
file_to_print = objFS.GetAbsolutePathName(file_to_print)
wrk_folder = objFS.GetParentFolderName(file_to_print) & "\"

wscript.echo "Argument passed: " & wscript.arguments(0)
wscript.echo "Absolute file path: " & file_to_print
wscript.echo "Work folder: " & wrk_folder & vbcrlf

if objFS.FileExists(file_to_print) then
    Set fldr = shl.Namespace(wrk_folder)
    Set files = fldr.Items

    For Each file in files
      If LCase(file.Path) = LCase(file_to_print) Then
        file.InvokeVerbEx("Print")
      End If

    Next
end if

Set shl = Nothing
Set fldr = Nothing
Set files = Nothing
Set objFS = Nothing

WScript.Quit

The PRINT.COM command only works with text files. It will print anything that is pure text, such as .TXT, .INI, .BAT, etc.

If your program supports print to file, you can use the PRINT.COM command to send those files to your printer.