none
I have the printer's IP address and name how to install it? RRS feed

  • Question

  • I have got the ip address and PID of the network printer, what method does C# have to install it?
    Thursday, November 7, 2019 5:34 AM

Answers

  • Hi Cooper-L, 

    Thank you for posting here.

    According to your question, I make a test on my side, and I successfully install a printer by it’s name and IP address.

    Here’s the code.

                static void Main(string[] args)
                {
                    using (var session = CimSession.Create("localhost"))
                    {
                        using (var cimMethodParameters = new CimMethodParametersCollection())
                        {
                            cimMethodParameters.Add(CimMethodParameter.Create("Name", @"\\Your printer’s IPaddress\PrinterName", CimFlags.Parameter));
                            session.InvokeMethod(@"root\cimv2", "Win32_Printer", "AddPrinterConnection", cimMethodParameters);
                        }
                    }
    
                    Console.ReadLine();
                }
    

    You need to add ‘Microsoft.Management.Infrastructure.dll’ reference in your program and you can find the dll in this path: ( C:\Program Files (x86)\Reference Assemblies\Microsoft\WMI\v1.0 ).

    Here’s the reference you can refer to.

    add printer to local computer using ManagementClass

    Best Regards,

    Xingyu Zhao



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 8, 2019 2:16 AM
    Moderator