In case of a new PC I need to get a list of available/connected printers and allow the user to add them, basically doing the "Add printer" functionality from the Printers & Scanners window.
Can I do this functionality of a Scan and Add printers in .NET. Are there any libraries which could help me in listing the available printers so that I can select that printer and install?
I came across a solution Add-Printer using WMI or PowerShell which does this, but it only adds a PrintQueue. Is the PrintQueue and Printer same or do i need to do something else after creating a PrintQueue in order to actually connect a printer to the PrintQueue.
I need to add printer on a freshly installed PC. I need to add printer using TCP/IP Port.
Loading
ROHAN MENDONCAPosted Feb 2, 2022, 1:26 PM
Muhammad Imran Ansari
I don't get those details in Win32_Printer. Win32_Printer gives you already installed PrintQueues.
I need to get the printers available for installation.
I need to do a functionality similar to what Windows does when you click on Printers & Scanners and click on Add Printers (+) button where it shows the available printers to install. I need to get those details and show those details in the UI for users.
Muhammad Imran AnsariPosted Feb 2, 2022, 10:57 AM
Yes. You can get the list of Printers using the following code
// NETFramework\v4.7.2\System.Management.dll
// Install System.Management from Nuget Package System
List listPrinters = new List();
ManagementObjectSearcher MOS = new ManagementObjectSearcher("Select * from win32_Printer");
ManagementObjectCollection MOC = MOS.Get();
foreach (ManagementObject mo in MOC)
{
listPrinters.Add(mo["Name"].ToString());
}
You can check the all properties of Win32_Printer class from the following link:
https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printer