Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following is an example of using the System.Management namespace to access WMI and print a Test Page to a Printer. This relies on the Printer being connected to the Computer, I can provide code for connecting a Network printer through System.Management if you want that as well. This code should work for any version of the .Net Framework</p> <pre><code>using System; using System.Management; public class PrintTestPageUsingWMI { private String _name; private ManagementObject _printer = null; public PrintTestPageUsingWMI(String printerName) { this._name = printerName; //Find the Win32_Printer which is a Network Printer of this name //Declare WMI Variables ManagementObject MgmtObject; ManagementObjectCollection MgmtCollection; ManagementObjectSearcher MgmtSearcher; //Perform the search for printers and return the listing as a collection MgmtSearcher = new ManagementObjectSearcher("Select * from Win32_Printer"); MgmtCollection = MgmtSearcher.Get(); foreach (ManagementObject objWMI in MgmtCollection) { if (objWMI.Item("sharename").ToString().Equals(this._name)) { this._printer = objWMI; } } if (this._printer == null) { throw new Exception("Selected Printer is not connected to this Computer"); } } public void PrintTestPage() { this.InvokeWMIMethod("PrintTestPage"); } /// &lt;summary&gt; /// Helper Method which Invokes WMI Methods on this Printer /// &lt;/summary&gt; /// &lt;param name="method"&gt;The name of the WMI Method to Invoke&lt;/param&gt; /// &lt;remarks&gt;&lt;/remarks&gt; private void InvokeWMIMethod(String method) { if (this._printer == null) { throw new Exception("Can't Print a Test Page on a Printer which is not connected to the Computer"); } Object[] objTemp = new Object[0] { null }; ManagementObject objWMI; //Invoke the WMI Method this._printer.InvokeMethod(method, objTemp); } } </code></pre> <p>Alternatively you could look at the System.Printing Namespace which is supported in .Net 3.0 and higher</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload