(view source code of print.vbs as plain text)
' Check the command line argumentsIf WScript.Arguments.Unnamed.Count <> 1 Then Syntax
If WScript.Arguments.Named.Count > 0 Then Syntax
' Check if a valid file was specifiedSet objFSO = CreateObject( "Scripting.FileSystemObject" )
strFile = WScript.Arguments(0)
If Not objFSO.FileExists( strFile ) Then Syntax
strFolder = objFSO.GetParentFolderName( strFile )
Set objFSO = Nothing
' Open the Shell Folders objectSet objShell = CreateObject( "Shell.Application" )
' Create an object for the specified file's parent folderSet objFolder = objShell.Namespace( strFolder )
' Create a collection for the folder's contentsSet colFiles = objFolder.Items
' Loop through the collection to find the file specifiedIf colFiles.Count > 0 Then
For Each objFile In colFiles
If LCase( objFile.Path ) = LCase( strFile ) Then
' Print the file with its associated print commandobjFile.InvokeVerbEx( "Print" )
End If
NextEnd If
Sub Syntax Dim strMsgstrMsg = "Print.vbs, Version 1.00" _
& vbCrLf _& "Print a file - ANY file - on the default printer" _
& vbCrLf & vbCrLf _
& "Usage: " & UCase( WScript.ScriptName ) & " filename" _
& vbCrLf & vbCrLf _
& "Where: ""filename"" specifies the file to be printed (no wildcards)" _
& vbCrLf & vbCrLf _
& "Notes: This script will only work if a print command for the" _
& vbCrLf _& " file's associated file type is defined in the registry." _
& vbCrLf _& " When the associated program is used to open and print" _
& vbCrLf _& " the file, the program will not be closed automatically." _
& vbCrLf _& " This script may conflict with my DefOpen.bat script." _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" _
& vbCrLf _& "http://www.robvanderwoude.com"
WScript.Echo strMsg
WScript.Quit 1
End Sub
page last modified: 2025-10-11; loaded in 0.0081 seconds