I see references and hints that programmatically one can add a networked printer to a local computer using the ManagementClass and such. However I have not been able to find any actual tutorials on doing just this.
has anyone actually used the ManagementClass to do this?
I am doing this:
var connectionOption = new ConnectionOption();
var mgmScope = new ManagementScope("rootcimv2",connectionOptions);
var printerClass = new ManagementClass(mgmScope, new ManagementPath("Win32_Printer"),null);
var printerObj = printerClass.CreateInstance();
printerObj["DeviceID"] = prnName; //
printerObj["DriverName"] = drvName; // full path to driver
printerObj["PortName"] = "myTestPort:";
var options = new PutOptions {Type = PutType.UpdateOrCreate};
printerObj.Put(options);
All this does is create an error "Generic Failure"
I cant figure out what I am missing..... any help or thoughts about this would be appreciated.
I think I need to better explain what I am trying to do... when the printers needed are not tied to a print server, I need to:
create a tcpip raw port,
connect a printer via tcp/ip,
install drivers,
optionally set default.
I was hoping WMI could basically take care of all of this but it doesnt appear to be the case.
thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…