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. AddPrinterConnection failing to add network printer

AddPrinterConnection failing to add network printer

Scheduled Pinned Locked Moved C#
sysadminworkspacecsharpvisual-studiocom
2 Posts 1 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.
  • E Offline
    E Offline
    ekynox
    wrote on last edited by
    #1

    Hi guys, have been playing with WMI to add a network printer connection to a Windows XP pc. My environment consists of a server running Windows Server 2003 and Visual Studio 2005 and a test pc running windows xp. Further, I have setup a full domain controller environment. I have managed to write the code to add the network printer and it works fine when installing the printer on the same machine the code is executing from i.e the server or xp pc. However, if I run the code from the server to install the network printer onto the test pc, it does not work. An exception is generated stating "Not Supported, the inner exception is blank. I can manually install the network printer on the test pc via the control panel, proving that the connectivity between machines is fine. The exception occurs when the mgtClass.InvokeMethod is executed. 1) If I specifiy the ip address of the test pc in the ManagementScope object does and when an object of Management class is instantiated does this imply that the network printer will be added to the test pc? 2)Using the AddPrinterConnection method from the WIN32_PRINTER class, is this the only way to add a network printer ? 3) To install the network printer on the server itself, omit the IP address,ipAddressOfClientPC, of the server from the ManagementScope object and it installs fine, provided the code itself is running of the server. So this leads me to believe its an issue with ManagementScope. However, if installing on the same machine as the code is running on then the username and password need not to be defined. So what do I need to do to the Management Scope object to make it work? I used the WMI code generated by the WMI Code Generator, http://www.microsoft.com/downloads/details.aspx?FamilyID=2cc30a64-ea15-4661-8da4-55bbc145c30e, I have added my code below. If somone can point me in the right direction as to the mistake I am making, I would appreciate it. thanks V using System; using System.Management; using System.Runtime.InteropServices; using System.Text; namespace SampleApp { public class AddPrinterConnection { public static void Main() { //only required if required to access another machine with different username and password string username = "administrator"; string password = "password"; string ipAddressOfClientPC = "192.168.0.22"; ManagementScope scope = new ManagementScope("\\\\" + ipAddressOfClientPC + "\\root\\cimv2");

    E 1 Reply Last reply
    0
    • E ekynox

      Hi guys, have been playing with WMI to add a network printer connection to a Windows XP pc. My environment consists of a server running Windows Server 2003 and Visual Studio 2005 and a test pc running windows xp. Further, I have setup a full domain controller environment. I have managed to write the code to add the network printer and it works fine when installing the printer on the same machine the code is executing from i.e the server or xp pc. However, if I run the code from the server to install the network printer onto the test pc, it does not work. An exception is generated stating "Not Supported, the inner exception is blank. I can manually install the network printer on the test pc via the control panel, proving that the connectivity between machines is fine. The exception occurs when the mgtClass.InvokeMethod is executed. 1) If I specifiy the ip address of the test pc in the ManagementScope object does and when an object of Management class is instantiated does this imply that the network printer will be added to the test pc? 2)Using the AddPrinterConnection method from the WIN32_PRINTER class, is this the only way to add a network printer ? 3) To install the network printer on the server itself, omit the IP address,ipAddressOfClientPC, of the server from the ManagementScope object and it installs fine, provided the code itself is running of the server. So this leads me to believe its an issue with ManagementScope. However, if installing on the same machine as the code is running on then the username and password need not to be defined. So what do I need to do to the Management Scope object to make it work? I used the WMI code generated by the WMI Code Generator, http://www.microsoft.com/downloads/details.aspx?FamilyID=2cc30a64-ea15-4661-8da4-55bbc145c30e, I have added my code below. If somone can point me in the right direction as to the mistake I am making, I would appreciate it. thanks V using System; using System.Management; using System.Runtime.InteropServices; using System.Text; namespace SampleApp { public class AddPrinterConnection { public static void Main() { //only required if required to access another machine with different username and password string username = "administrator"; string password = "password"; string ipAddressOfClientPC = "192.168.0.22"; ManagementScope scope = new ManagementScope("\\\\" + ipAddressOfClientPC + "\\root\\cimv2");

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

      It seems that AddPrinterConnection method is reserved for adding network printers to local machines rather than remote machines as to what I was trying to achieve. To add network printer on remote machines you need to use rundll32 printui.dll,PrintUIEntry /?. This is a command line method of doing things however it can be easily incorporated into managed code.

      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