asp.net network printer not showing the zebra printers? - c#

Hi i have a method that gets a printer list from the network and fill my drop-down list:
private void fillprinterslist()
{
System.Management.ManagementScope objMS =
new System.Management.ManagementScope(ManagementPath.DefaultPath);
objMS.Connect();
SelectQuery objQuery = new SelectQuery("SELECT * FROM Win32_Printer");
ManagementObjectSearcher objMOS = new ManagementObjectSearcher(objMS, objQuery);
System.Management.ManagementObjectCollection objMOC = objMOS.Get();
foreach (ManagementObject Printers in objMOC)
{
if (Convert.ToBoolean(Printers["Network"])) // ALL NETWORK PRINTERS.
{
DropDownList3.Items.Add(Printers["Name"].ToString());
}
}
}
not all network printers are getting filled in the drop down list, for example i have an zebra label printer in the next room that i am using as a test for this project and it does not show up in the drop down list
the printer is located on:
\ksmsv010\kcmzbl63
In my drop down list i am able to see other printers that are not Zebra Printers
**how do i only list the zebra printers from all servers?? **
from what information i had all the zebra printers have "zbl" common in the naming convention so i dont know if we can filter based on those 3 letter.
Please help thanks!!!!

Related

How can I find out what graphic card a screen is connected to in C#?

I need to programatically find out what graphic card a screen is connected to using C#.
This information is visible in DxDiag, speccy and even in windows advanced display settings view:
But how can I do this in C# myself?
The following is code by #NielW in C# detect which graphics card drives video
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController");
foreach (ManagementObject mo in searcher.Get())
{
PropertyData currentBitsPerPixel = mo.Properties["CurrentBitsPerPixel"];
PropertyData description = mo.Properties["Description"];
if (currentBitsPerPixel != null && description != null)
{
if (currentBitsPerPixel.Value != null)
System.Console.WriteLine(description.Value);
}
}
}
There is a long talk in the link because they have issues getting multiples graphic cards' names. But this code should work and it shows all names of available graphic cards.

PrintQueue.Refresh don't show the status of printer

I need to run a Windows Service of server X to show the status of all printers: Out of paper, no toner, etc.
The service is running on a machine but of course not all printers are installed on it. Even when the printers are installed on the machine, we do NOT have the status of the printers!
The only thing I was able to do is to remove the paper, print a test page (notepad), and now I can see that I'm missing paper with the code below, but as you might thing, this is not doable: I don't want to send a test page to every printers of the network every 10 minutes or so!
I try to query PrintQueue.Refresh but status is not updating, I don't see that the printer tray is open (or missing paper, or no toner, whatever I do with the printer.)
BTW, Win32_printer don't show me a better result.
NOTE:
MonitoringWS is the web service that can access the database.
Printers is the list of printers that we want to query.
This is what I try to do.
var printServers = GetListOfPrinterServers();
var listPrinters = printers as List<Printer> ?? printers.ToList();
foreach (
var printServer in
printServers.Select(
server => new PrintServer(server, PrintSystemDesiredAccess.EnumerateServer)))
{
printServer.Refresh();
var printQueues = printServer.GetPrintQueues();
foreach (var printQueue in printQueues)
{
var queue = printQueue;
var printersFound = listPrinters.Where(p =>
string.Equals(p.PrinterName, queue.FullName,
StringComparison.OrdinalIgnoreCase));
foreach (var printer in printersFound)
{
printQueue.Refresh();
Debug.WriteLine(string.Format("{0} {1}", printQueue.FullName, printQueue.HostingPrintServer.Name) );
var pm = new MonitoringWS.PrinterMonitoring
{
FkPrinter = printer.PkPrinter,
QueueStatus = printQueue.QueueStatus,
DriverName = printQueue.QueueDriver.Name,
MonitoringDateTime = DateTime.Now
};
printerMonitorings.Add(pm);
}
}
}
I found a way: SNMP. I use library SNMP# at http://www.snmpsharpnet.com/ and I implement RFC 2790: https://www.rfc-editor.org/rfc/rfc2790 .
With that, when the printer support that standard and when SNMP is active, I got the status of the printer (no toner, no paper, paper jam, etc.)
Thanks everybody for your help.

Incorrect hard drive serial number

I am currently developing a program that will allow me to detect the serial number of all hard drives in a computer and display them as a barcode.
I have it working on my current machine (Windows 10) and it gets the correct serial numbers (same as what's on the hard drive label) but when I try and use it on a different machine (Windows 7) it just outputs a long string of numbers.
The program is able to detect and output the serial number on my usb fine.
var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
foreach (ManagementObject wmi_HD in searcher.Get())
{
HardDrive hd = new HardDrive();
hd.Model = wmi_HD["Model"].ToString();
hd.SerialNum = Convert.ToString(wmi_HD.GetPropertyValue("SerialNumber"));
hdCollection.Add(hd);
}
This is the current code I am using but the serial number it outputs is: 5635454d4338414e202020202020202020202020
I have tried Win32_LogicalDrive and Win32_Volume but they output the same string.
I have also tried this code snippet:
ManagementClass driveClass = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection drives = driveClass.GetInstances();
foreach (ManagementObject drive in drives)
{
HardDrive hd = new HardDrive();
hd.Model = drive["Name"].ToString();
//hd.SerialNum = drive.GetPropertyValue("SerialNumber").ToString();
hd.SerialNum = drive["SerialNumber"].ToString();
}
But this also does not work on the Windows 7 machine.
How could I fix my problem?

C# Application: Get Network Shares On Another Computer

First of all, apologies if this doesn't make sense, and/or it has already been asked (although searching didn't find anything).
I have an application which sets default printers for our end users but I would like to expand it by also making it able to install printers from a remote machine as well.
What I need to do is on Form_Load populate a Combo Box with all network shares from the print server.
I am shooting in the dark and am wondering if anyone can shed some light.
I believe this works.
This isnt my code originally but I cant remember where it came from.
using System.Management;
private void btnGetPrinters_Click(object sender, EventArgs e) {
// Use the ObjectQuery to get the list of configured printers.
ObjectQuery oquery = new ObjectQuery("SELECT * FROM Win32_Printer");
ManagementObjectSearcher mosearcher = new ManagementObjectSearcher(oquery);
ManagementObjectCollection moc = mosearcher.Get();
foreach (ManagementObject mo in moc)
{
PropertyDataCollection pdc = mo.Properties;
foreach (System.Management.PropertyData pd in pdc)
{
if ((bool)mo["Network"])
{
cmbPrinters.Items.Add(mo[pd.Name]);
}
}
}
}

Detecting input and output audio devices separately in C#

I am trying to search for all available sound input and outut devices and adding their names into a ComboBox.
I am using this code (found here at stackoverflow in a similiar question):
ManagementObjectSearcher mo = new ManagementObjectSearcher("select * from Win32_SoundDevice");
foreach (ManagementObject soundDevice in mo.Get())
{
string deviceId = soundDevice.GetPropertyValue("DeviceId").ToString();
string name = soundDevice.GetPropertyValue("Name").ToString();
comboBox1.Items.Add(name);
}
But this seems to select all available devices, I need to separate input devices and output devices. Is there a simple way of editing this code, or is there a more sophisticated method needed?

Categories