Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
i am working with project called print monitoring tool.Using this application we can get a control on the printing device so that we can calculate the printouts
And collect the print details.my problem is i dont know how to connect print server in lan using wmi.is anyone know how to do it????
Posted

As far as I know, printers don't have much of Windows OS on them, let alone run Windows Management Instruments service... But mostly they do have SNMP service which you can query via UDP port 161. The SNMP packages are easy to send-receive etc but MIB database is the problem. You need to know which object on target to query. For Instance object ID "1.3.6.1.2.1.43" is printer node in MIB. Check out Simple Network Management Protocol[^] for more info.
 
Share this answer
 
Comments
Kim Togo 3-May-11 15:14pm    
Good answer, my 5. Using SNMP to query for status/info directly at the printer is a good solution.
If the computer is printing using a Windows Server and not directly to the printer, then perhaps a program on the Windows server can collect info?

But I would go after SNMP.
yesotaso 4-May-11 9:05am    
Thank you! Indeed this only applies to network print servers like HP jet direct. For the printers shared to network via Windows machine WMI is the way.
RaviRanjanKr 4-May-11 1:13am    
Nice Answer, My vote of 5 :)
yesotaso 4-May-11 9:05am    
Thank you sir.
static void GetpriterDetails()
        {
            bool online = false;
            string strQuery = "SELECT * FROM Win32_Printer";

            ObjectQuery objectQuery = new ObjectQuery(strQuery);
            ManagementObjectSearcher query = new ManagementObjectSearcher(objectQuery);
            ManagementObjectCollection queryCollection = query.Get();

            foreach (ManagementObject managementObject in queryCollection)
            {
                if (managementObject != null)
                {
                    string str = string.Empty;
                    string printerName = "\\\\SEBP20\\WiproEX3";
                    str = managementObject["Name"].ToString().ToLower();
                    if (!str.Contains('\\'))
                    {
                        string MyPCname = string.Empty;

                        if (printerName.Contains('\\'))
                        {
                            string[] MyPCname1 = printerName.Split('\\');
                            MyPCname = MyPCname1[2];
                        }

                        str = "\\\\" + MyPCname + "\\" + str;

                    }

                    if (str.ToUpper().Equals(printerName.ToUpper()))
                    {
                        if (managementObject["WorkOffline"].ToString().ToLower().Equals("true") || managementObject["PrinterStatus"].Equals(7))
                        {
                            //--it's offline
                            online = false;
                        }
                        else
                        {
                            //--it's online
                            online = true;
                        }
                    }
                }
                else
                {
                    throw new Exception("No printers were found");
                }
            }
        }
 
Share this answer
 
v2
Comments
RaviRanjanKr 4-May-11 0:41am    
Hey Anvas, Always Wrap your code in "pre" tags.
anvas kuttan 4-May-11 0:43am    
ok i will do from now it self thank you for your advc
You might want to start from here[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900