Windows Scripting
  Home arrow Windows Scripting arrow Printing Documents in WSH
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Printing Documents in WSH
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2008-07-07

    Table of Contents:
  • Printing Documents in WSH
  • Determining the System Default Printer
  • Setting the System Default Printer
  • Shell Printing and Printing with Notepad
  • Printing Word and PDF Documents
  • Printing Web Documents
  • Printing Web Documents continued

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Printing Documents in WSH


    (Page 1 of 7 )

    Printing documents is a fairly common automation task. Perhaps you want to batch print a folder full of documents, or maybe you’d like to automate report printing. In any case, WSH doesn’t necessarily provide a straightforward method for doing this. Let’s look at some different ways of printing documents in WSH.

    The majority of methods that we’ll be using to print will rely on the system’s default printer setting.  In order to change printers, you’ll need to be able to detect and set this system setting.  There are a number of ways to do this as you will see shortly.

    First, let’s take a look at how WMI can be used to view information about installed printers.

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:" _

       & "{impersonationLevel=impersonate}!" & strComputer _

           & "rootcimv2")

    We’ll begin by connecting to the local WMI service at the rootcimv2 namespace.  This type of connection should look pretty familiar to you if you’ve used WMI at all in the past.

    Set colInstalledPrinters = objWMIService.ExecQuery( _

       "Select * from Win32_Printer")

    Next, we execute a query that polls all instances of the Win32_Printer class.  This class returns a collection object containing a reference to each installed printer.

    For Each objPrinter In colInstalledPrinters

       WScript.Echo objPrinter.Name

    Next

    Now we’re able to use a simple For…Next loop to iterate through the collection of installed printers and print the name.  “Why is this important?” You ask.  It gives you a chance to see the naming conventions that you’ll be using throughout the rest of this article.

    More Windows Scripting Articles
    More By Nilpo


       · There's plenty of reason why you might want your script to print documents. Maybe...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek