Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 944503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:36:11+00:00 2026-05-15T22:36:11+00:00

In a LAN normally printers are shared, and we can add these shared computers

  • 0

In a LAN normally printers are shared, and we can add these shared computers in the LAN to our machine through Windows “Add Remote Printer”. I want to get the list of added printer like this, and there online status and printer settings through C#. The list of added printers could be obtained by

System.Drawing.Printing.PrinterSettings.InstalledPrinters

through this code I can get the list of added printers to a combobox. The problem is how can I get the online status of each printer, and there other possible settings through the c# code. Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:36:12+00:00Added an answer on May 15, 2026 at 10:36 pm

    As an alternative to WMI, you can use the Print Spooler API to gather detailed information about the printers. Most of the P/Invoke signatures for the API are available on http://www.pinvoke.net.

    Open a handle to a printer:
    http://www.pinvoke.net/default.aspx/winspool.OpenPrinter

    Gather printer information:
    http://www.pinvoke.net/default.aspx/winspool.GetPrinterData

    Edit:

    Quickly smashed together an example of what you can gather from the PrintSpoolerApi as per request.

    PrintSpoolerAPIExample:

    Create new console project and replace all code in Program.cs with this (.NET 3.5 and above, due to type inference), the printer details of each printer available on the machine (local or networked) will be printed to the console. The status value is what you are interested in. The status code for “Ready” is 0, mess around by disabling printers and disabling your network connection to networked printers to see the status change.

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Runtime.InteropServices;
    using System.Text;
    
    namespace PrintSpoolerAPIExample
    {
        class Program
        {
            static void Main(string[] args)
            {
                var printers = System.Drawing.Printing.PrinterSettings.InstalledPrinters as IEnumerable;
    
                foreach (string printer in printers)
                {
                    var printerInfo = PrintSpoolerApi.GetPrinterProperty(printer);
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine(string.Format("ServerName:{0}", printerInfo.ServerName));
                    sb.AppendLine(string.Format("PrinterName:{0}", printerInfo.PrinterName));
                    sb.AppendLine(string.Format("ShareName:{0}", printerInfo.ShareName));
                    sb.AppendLine(string.Format("PortName:{0}", printerInfo.PortName));
                    sb.AppendLine(string.Format("DriverName:{0}", printerInfo.DriverName));
                    sb.AppendLine(string.Format("Comment:{0}", printerInfo.Comment));
                    sb.AppendLine(string.Format("Location:{0}", printerInfo.Location));
                    sb.AppendLine(string.Format("DevMode:{0}", printerInfo.DevMode));
                    sb.AppendLine(string.Format("SepFile:{0}", printerInfo.SepFile));
                    sb.AppendLine(string.Format("PrintProcessor:{0}", printerInfo.PrintProcessor));
                    sb.AppendLine(string.Format("Datatype:{0}", printerInfo.Datatype));
                    sb.AppendLine(string.Format("Parameters:{0}", printerInfo.Parameters));
                    sb.AppendLine(string.Format("Attributes:{0}", printerInfo.Attributes));
                    sb.AppendLine(string.Format("Priority:{0}", printerInfo.Priority));
                    sb.AppendLine(string.Format("DefaultPriority:{0}", printerInfo.DefaultPriority));
                    sb.AppendLine(string.Format("StartTime:{0}", printerInfo.StartTime));
                    sb.AppendLine(string.Format("UntilTime:{0}", printerInfo.UntilTime));
                    sb.AppendLine(string.Format("Status:{0}", printerInfo.Status));
                    sb.AppendLine(string.Format("Jobs:{0}", printerInfo.Jobs));
                    sb.AppendLine(string.Format("AveragePpm:{0}", printerInfo.AveragePpm));
                    Console.WriteLine(sb.ToString());
                }
    
                Console.ReadLine();
            }
        }
    
        class PrintSpoolerApi
        {
            [DllImport("winspool.drv", SetLastError = true, CharSet = CharSet.Auto)]
            public static extern bool OpenPrinter(
                [MarshalAs(UnmanagedType.LPTStr)]
                string printerName,
                out IntPtr printerHandle,
                PrinterDefaults printerDefaults);
    
            [DllImport("winspool.drv", SetLastError = true, CharSet = CharSet.Auto)]
            public static extern bool GetPrinter(
                IntPtr printerHandle,
                int level,
                IntPtr printerData,
                int bufferSize,
                ref int printerDataSize);
    
            [DllImport("winspool.drv", SetLastError = true, CharSet = CharSet.Auto)]
            public static extern bool ClosePrinter(
                IntPtr printerHandle);
    
            [StructLayout(LayoutKind.Sequential)]
            public struct PrinterDefaults
            {
                public IntPtr pDatatype;
                public IntPtr pDevMode;
                public int DesiredAccess;
            }
    
            public enum PrinterProperty
            {
                ServerName,
                PrinterName,
                ShareName,
                PortName,
                DriverName,
                Comment,
                Location,
                PrintProcessor,
                Datatype,
                Parameters,
                Attributes,
                Priority,
                DefaultPriority,
                StartTime,
                UntilTime,
                Status,
                Jobs,
                AveragePpm
            };
    
            public struct PrinterInfo2
            {
                [MarshalAs(UnmanagedType.LPTStr)]
                public string ServerName;
                [MarshalAs(UnmanagedType.LPTStr)]
                public string PrinterName;
                [MarshalAs(UnmanagedType.LPTStr)]
                public string ShareName;
                [MarshalAs(UnmanagedType.LPTStr)]
                public string PortName;
                [MarshalAs(UnmanagedType.LPTStr)]
                public string DriverName;
                [MarshalAs(UnmanagedType.LPTStr)]
                public string Comment;
                [MarshalAs(UnmanagedType.LPTStr)]
                public string Location;
                public IntPtr DevMode;
                [MarshalAs(UnmanagedType.LPTStr)]
                public string SepFile;
                [MarshalAs(UnmanagedType.LPTStr)]
                public string PrintProcessor;
                [MarshalAs(UnmanagedType.LPTStr)]
                public string Datatype;
                [MarshalAs(UnmanagedType.LPTStr)]
                public string Parameters;
                public IntPtr SecurityDescriptor;
                public uint Attributes;
                public uint Priority;
                public uint DefaultPriority;
                public uint StartTime;
                public uint UntilTime;
                public uint Status;
                public uint Jobs;
                public uint AveragePpm;
            }
    
            public static PrinterInfo2 GetPrinterProperty(string printerUncName)
            {
                var printerInfo2 = new PrinterInfo2();
    
                var pHandle = new IntPtr();
                var defaults = new PrinterDefaults();
                try
                {
                    //Open a handle to the printer
                    bool ok = OpenPrinter(printerUncName, out pHandle, defaults);
    
                    if (!ok)
                    {
                        //OpenPrinter failed, get the last known error and thrown it
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }
    
                    //Here we determine the size of the data we to be returned
                    //Passing in 0 for the size will force the function to return the size of the data requested
                    int actualDataSize = 0;
                    GetPrinter(pHandle, 2, IntPtr.Zero, 0, ref actualDataSize);
    
                    int err = Marshal.GetLastWin32Error();
    
                    if (err == 122)
                    {
                        if (actualDataSize > 0)
                        {
                            //Allocate memory to the size of the data requested
                            IntPtr printerData = Marshal.AllocHGlobal(actualDataSize);
                            //Retrieve the actual information this time
                            GetPrinter(pHandle, 2, printerData, actualDataSize, ref actualDataSize);
    
                            //Marshal to our structure
                            printerInfo2 = (PrinterInfo2)Marshal.PtrToStructure(printerData, typeof(PrinterInfo2));
                            //We've made the conversion, now free up that memory
                            Marshal.FreeHGlobal(printerData);
                        }
                    }
                    else
                    {
                        throw new Win32Exception(err);
                    }
    
                    return printerInfo2;
                }
                finally
                {
                    //Always close the handle to the printer
                    ClosePrinter(pHandle);
                }
            }
        }
    }
    

    You can retrieve even more details from the API, if required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can pipes be used across LAN computers? In particular I'm looking for Windows, but
I have Oracle running on one machine of the LAN. I can connect to
I want to develop simple Serverless LAN Chat program just for fun. How can
I have a svn server on our lan locally its on windows. The developers
I want to run simple HTTP server on LAN to test it, how can
In the Lan connected printer, I want to print the files in sd card
Inside the LAN, we are good to go… folks access our intranet using http://
I have three computers on my LAN, one running ubuntu , one running openSuse
By enabling Wake-on-LAN on my PC, I can remotely power it on. Suppose I
I'm developing a wake up on LAN project but that I want to control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.