c# - How to print a test page and capture the return value for a non default printer on a remote server using WMI's PrintTestPage method? -
i'm using system.management namespace along wmi install printers/ports on remote server. once printer/port installed, i'd print test page, capture whether or not printing test page (theoretically) successful, , display result user. i've got working until point of printing test page.
i've seen this article, this article, on subject, neither 1 quite seems doing trick because i'm not seeing how apply them current printer i've installed.
anyway, here's code i'm working install printer (the port code similar , not necessary...there's additional code i'm using log in remote server, long know i'm creating managementscope object connectionoptions object attached, there's no reason show code either):
foreach (printers p in lstprinters) { search = printerquery + "'" + p.printername + "'"; query = new selectquery(search); try { using (var searcher = new managementobjectsearcher(scope, query)) { managementobjectcollection printers = searcher.get(); objectgetoptions oprinteroptions = new objectgetoptions(null, timespan.maxvalue, true); managementpath mpathprinter = new managementpath("win32_printer"); managementclass mclassprinter = new managementclass(scope, mpathprinter, oprinteroptions); managementobject mnewprinter = mclassprinter.createinstance(); mnewprinter["comment"] = p.comment; mnewprinter["deviceid"] = p.deviceid; mnewprinter["drivername"] = p.drivername; mnewprinter["location"] = p.location; mnewprinter["network"] = p.network; mnewprinter["portname"] = p.portname; mnewprinter["shared"] = p.shared; mnewprinter["sharename"] = p.sharename; // if no ports returned, add port. // otherwise, update current port object. putoptions poputprinter = new putoptions(); poputprinter.type = puttype.updateorcreate; poputprinter.useamendedqualifiers = true; mnewprinter.put(poputprinter); } } }
i thought able this...which similar example in second article link listed above:
managementbaseobject retvalue = mnewprinter.invokemethod("printtestpage", null); if (convert.toint32(retvalue["returnvalue"]) == 0) { messagebox.show("test page printed successfully."); }
in theory, @ least in head, above ensure that, assigning mnewprinter
managementobject variable invokemethod, printtestmethod linked printer on specific server.
thanks...
i think solved own question using following:
managementbaseobject outparams = mnewprinter.invokemethod("printtestpage", null, null); if (convert.toint32(outparams["returnvalue"]) == 0) { messagebox.show("test page printed successfully."); }
for reason, had add null mnewprinter.invokemethod("printtestpage, null)
. otherwise, returning error.
Comments
Post a Comment