Share This!

Wednesday, August 15, 2007

Adding a printer

How to programmatically add a printer.

This will show how to add a printer to the current Windows workstation's Printers and faxes page. This will effectively render the printer usable by the workstation.

Here's the code example.

using System.Runtime.InteropServices;

namespace WindowsApplication1
    public partial class Form1 : Form
        [DllImport("winspool.drv", SetLastError=true)]
        public static extern bool AddPrinterConnection(string pName);

        public Form1()

        private void button1_Click(object sender, EventArgs e)
            if (AddPrinterConnection("\\\\PrintServer\\PrinterName"))
            { MessageBox.Show("ok"); }
                throw new Win32Exception();

No comments:

Post a Comment

Contact Us


Email *

Message *