Groups | Blog | Home
all groups > dotnet clr > february 2004 >

dotnet clr : Adding Printer and Printer Ports (report from framework group)


David Williams
2/11/2004 8:34:02 PM
I have been attempting to find a way to [programmically] add printers to a
server. This requires that a new port be added. I have not been able to
find a means to accomplish this.

I did find some *old* posts for using the AddPortEx/AddPrinter APIs from the
winspool.drv, however, while I can get these to run, they do nothing (i.e.
no entries entered in to the registry, and the port and printers are not
found on the control panel.) I have confirmed that there is no registry
activaty happenning using RegMon. ClrSpy tells me that I have an incorrect
calling convention, however, I have tried all combinations of calling
conventions to correct this and it did not.

I would think that something so often required (that of adding/deleting
printers and printer ports) would be in the framework. Can someone point me
in the right direction?

TIA

David

David Williams
2/12/2004 7:41:25 PM
Not to sound dumb or anything (though I am when it comes to WMI :) ), how
would I do this via WMI? I can see how to query for information, but I have
not seen anything that would let me add a printer port and printer. Can you
point me in the right direction for information on this (not that I would
mind if you just told me ;) ).

TIA

David

[quoted text, click to view]

kitg NO[at]SPAM ONLINE NO[at]SPAM microsoft.com
2/12/2004 7:57:26 PM
David, I know we're not planning on adding any specific support at this
time on the CLR team. However, you might want to redirect your question to
the windosforms newsgroup, to see if they are planning on adding support on
that side.

Regards,
Kit
Willy Denoyette [MVP]
2/12/2004 9:27:50 PM
You can do this using The System.Management classes and WMI.

Willy.
[quoted text, click to view]

corinaf NO[at]SPAM microsoft.com
2/25/2004 6:30:31 PM
Did you try using Win32_Printer::AddPrinterConnection method ?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/
addprinterconnection_method_in_class_win32_printer.asp describes the
method, and your .NET code would look something like this (might need some
adjustment :-) ) :


using System.Management;

ManagementClass printerClass = new ManagementClass("Win32_Printer");
object[] printerName = {"\\myServer\printer1"};
object result = printerClass.InvokeMethod ("AddPrinterConnection",
printerName );

Cori
AddThis Social Bookmark Button