Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for print.vbs

(view source code of print.vbs as plain text)

  1. ' Check the command line arguments
  2. If WScript.Arguments.Unnamed.Count <> 1 Then Syntax
  3. If WScript.Arguments.Named.Count    > 0 Then Syntax
  4.  
  5. ' Check if a valid file was specified
  6. Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  7. strFile = WScript.Arguments(0)
  8. If Not objFSO.FileExists( strFile ) Then Syntax
  9. strFolder = objFSO.GetParentFolderName( strFile )
  10. Set objFSO = Nothing
  11.  
  12. ' Open the Shell Folders object
  13. Set objShell  = CreateObject( "Shell.Application" )
  14.  
  15. ' Create an object for the specified file's parent folder
  16. Set objFolder = objShell.Namespace( strFolder )
  17.  
  18. ' Create a collection for the folder's contents
  19. Set colFiles  = objFolder.Items
  20.  
  21. ' Loop through the collection to find the file specified
  22. If colFiles.Count > 0 Then
  23. 	For Each objFile In colFiles
  24. 		If LCase( objFile.Path ) = LCase( strFile ) Then
  25. 			' Print the file with its associated print command
  26. 			objFile.InvokeVerbEx( "Print" )
  27. 		End If
  28. 	Next
  29. End If
  30.  
  31.  
  32. Sub Syntax
  33. 	Dim strMsg
  34. 	strMsg = "Print.vbs,  Version 1.00" _
  35. 	       & vbCrLf _
  36. 	       & "Print a file - ANY file - on the default printer" _
  37. 	       & vbCrLf & vbCrLf _
  38. 	       & "Usage:  " & UCase( WScript.ScriptName ) & "  filename"  _
  39. 	       & vbCrLf & vbCrLf _
  40. 	       & "Where:  ""filename""  specifies the file to be printed (no wildcards)" _
  41. 	       & vbCrLf & vbCrLf _
  42. 	       & "Notes:  This script will only work if a print command for the"   _
  43. 	       & vbCrLf _
  44. 	       & "        file's associated file type is defined in the registry." _
  45. 	       & vbCrLf _
  46. 	       & "        When the associated program is used to open and print"   _
  47. 	       & vbCrLf _
  48. 	       & "        the file, the program will not be closed automatically."          _
  49. 	       & vbCrLf _
  50. 	       & "        This script may conflict with my DefOpen.bat script."    _
  51. 	       & vbCrLf & vbCrLf _
  52. 	       & "Written by Rob van der Woude" _
  53. 	       & vbCrLf _
  54. 	       & "http://www.robvanderwoude.com"
  55. 	WScript.Echo strMsg
  56. 	WScript.Quit 1
  57. End Sub
  58.  

page last modified: 2024-04-16; loaded in 0.0083 seconds