on my app (win10, WPF) i give the user the possibility to print a report.
BUT
when there is not-yet-configured printer on the LOCAL machine - it is impossible.
(of course that the printer is activated on the network, and by using settings -> add printer & sccaners
it is found and installable)
i've searched the net for few days, looking for a way to:
1.
use ManagementObjectSearcher("SELECT * from Win32_Printer")
but got only localy installed printing options
2.
tried the following code - but i don't know the server or printer name
(i might know the network name where the user runs my app - but it can be any type of printer...)
using (ManagementClass win32Printer = new ManagementClass("Win32_Printer"))
{
using (ManagementBaseObject inputParam = win32Printer.GetMethodParameters("AddPrinterConnection"))
{
// Replace <server_name> and <printer_name> with the actual server and
// printer names.
inputParam.SetPropertyValue("Name", "\\\\<server_name>\\<printer_name>");
using (ManagementBaseObject result =
(ManagementBaseObject)win32Printer.InvokeMethod("AddPrinterConnection", inputParam, null))
{
uint errorCode = (uint)result.Properties["returnValue"].Value;
switch (errorCode)
{
case 0:
Console.Out.WriteLine("Successfully connected printer.");
break;
case 5:
Console.Out.WriteLine("Access Denied.");
break;
case 123:
Console.Out.WriteLine("The filename, directory name, or volume label syntax is incorrect.");
break;
case 1801:
Console.Out.WriteLine("Invalid Printer Name.");
break;
case 1930:
Console.Out.WriteLine("Incompatible Printer Driver.");
break;
case 3019:
Console.Out.WriteLine("The specified printer driver was not found on the system and needs to be downloaded.");
break;
}
}
}
}
after installing the printer drive (from windows
add printers & scanners
) i got the mac address of the printer then even after un-installing i could get its' IP-Address (as suggested here)
none of the above helped me...
therefore i'm looking for any possible way to install the new printer programmatically - such as:
- launch
PrintDialog
with "add new printer" option - open the
windows settings
window with theprinters & scanners
screen
found that:Process.Start("ms-settings:printers");
- install the new printer using any of the above data
- do it in any other way.......... :)