Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to connect to network printer via C#

How to connect to network printer via C#

Scheduled Pinned Locked Moved C#
tutorialquestioncsharpsysadmin
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    coleschuk
    wrote on last edited by
    #1

    Hi, How can I connect a network printer to a user session via C#??? For example: I want to connect "\\intranet\phaser" to my current user session and show up as a network-based printer in my local Printers and Faxes folder. Chris

    Z E 2 Replies Last reply
    0
    • C coleschuk

      Hi, How can I connect a network printer to a user session via C#??? For example: I want to connect "\\intranet\phaser" to my current user session and show up as a network-based printer in my local Printers and Faxes folder. Chris

      Z Offline
      Z Offline
      zhousz
      wrote on last edited by
      #2

      You should add the printer to your local

      1 Reply Last reply
      0
      • C coleschuk

        Hi, How can I connect a network printer to a user session via C#??? For example: I want to connect "\\intranet\phaser" to my current user session and show up as a network-based printer in my local Printers and Faxes folder. Chris

        E Offline
        E Offline
        ekynox
        wrote on last edited by
        #3

        you can actually use WMI to install a network based printer. Here is an example of how it is done using VB script http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec06/hey1212.mspx[^] To access WMI in C#, you need to access the System.Management namespace. If you are stuck post back here again.

        C 1 Reply Last reply
        0
        • E ekynox

          you can actually use WMI to install a network based printer. Here is an example of how it is done using VB script http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec06/hey1212.mspx[^] To access WMI in C#, you need to access the System.Management namespace. If you are stuck post back here again.

          C Offline
          C Offline
          coleschuk
          wrote on last edited by
          #4

          Thanks, but I got it. Here is what I did: [DllImport("winspool.drv")] public static extern bool AddPrinterConnection(string pName); [DllImport("winspool.drv")] public static extern bool SetDefaultPrinter(string printerName); bool result = AddPrinterConnection(@"\\server\printer"); bool resultdef = SetDefaultPrinter(@"\\server\printer"); Chris

          E P 2 Replies Last reply
          0
          • C coleschuk

            Thanks, but I got it. Here is what I did: [DllImport("winspool.drv")] public static extern bool AddPrinterConnection(string pName); [DllImport("winspool.drv")] public static extern bool SetDefaultPrinter(string printerName); bool result = AddPrinterConnection(@"\\server\printer"); bool resultdef = SetDefaultPrinter(@"\\server\printer"); Chris

            E Offline
            E Offline
            ekynox
            wrote on last edited by
            #5

            anychance you can explain how you managed to add a printer connection to a remote computer ?

            1 Reply Last reply
            0
            • C coleschuk

              Thanks, but I got it. Here is what I did: [DllImport("winspool.drv")] public static extern bool AddPrinterConnection(string pName); [DllImport("winspool.drv")] public static extern bool SetDefaultPrinter(string printerName); bool result = AddPrinterConnection(@"\\server\printer"); bool resultdef = SetDefaultPrinter(@"\\server\printer"); Chris

              P Offline
              P Offline
              Pallavi002
              wrote on last edited by
              #6

              Hi Chris, Thanks for the post! It worked for me. Just had to add namespace System.Runtime.InteropServices for DllImport i.e. using System.Runtime.InteropServices; Thanks again. Pallavi

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups