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
Kit George (MSFT) - 12 Feb 2004 19:57 GMT
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] - 12 Feb 2004 20:27 GMT
You can do this using The System.Management classes and WMI.
Willy.
>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
[quoted text clipped - 18 lines]
>
> David
David Williams - 13 Feb 2004 00:41 GMT
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
> You can do this using The System.Management classes and WMI.
>
[quoted text clipped - 21 lines]
> >
> > David
Corina Feuerstein - 25 Feb 2004 18:30 GMT
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