Using C# - I'm trying to find a list of all printers that are local and online (i.e. connected and ready to accept print requests)
I know the printer driver works - jobs will just wait until the printer is back online, but I need to find those specific that are online. These are clearly available to windows but the .net framework doesn't seem to accurately expose those which are currently online.
I'm trying to use lots of different methods and none seem to accurately work
// Get a list of available printers.
var printServer = new PrintServer();
var printQueues = printServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });
foreach (PrintQueue printQueue in printQueues)
{
Console.WriteLine(printQueue.IsOffline); // This works for IsOffline, but doesn't tell us those that are online - and it's not an inverse relationship
}
very frustrating - any help appreciated.
Should add I'm using windows 8.1, and the solution should work also with win 7+
Edit:
So given the following collection of printers :
I would expect to see something along the lines of
Getting all Printers
Send To OneNote 2013 : Online
Pack1 : Offine
Microsoft XPS Document Writer : Online
Fax : Online
EPSONB12B28 (XP-412 413 415 Series) : Offine
Brother MFC-9970CDW Printer : Online
But they are ALWAYS reported as Online on any status I see
I have queried just about every conceivable windows device either by native driver or using Windows Management Instrumentation (WMI) classes.
To get you started, take a read of this article with C# source: http://www.codeproject.com/Articles/80680/Managing-Printers-Programatically-using-C-and-WMI
Also, not in C# but VB, some quick glance info on the same subject here: http://msdn.microsoft.com/en-us/library/aa394598(v=vs.85).aspx
Full WMI reference here: http://msdn.microsoft.com/en-us/library/aa394572(v=VS.85).aspx
Cheers and good luck!
Related
Introduction
I have a Windows Phone 8.1 Silverlight (WP8.1 SL) based app in the store. Some users complain about performance issues when they have a bad network connection. I searched a bit and came up with the idea that it might be related to new LicenseInformation() that gives me the information of whether the app is running in Trial mode or not. The question is, whether this requires network information or not, and whether CurrentApp.LicenseInformation is a suitable replacement for a WP8.1 SL app.
Background and What I did so far
In general, the app does not need a network connection (no data to load, no advertisements, ...). To confirm that I used Fiddler to watch over the network sent by my phone. The result was that no network traffic is generated. However, the problem still persists.
After a lot of research and playing around I got the feeling that this issue might be related to the code part that checks on whether the app is in trial mode or not. I use the following code to check that.
var li = new LicenseInformation();
if (li.IsTrial()) {
...
}
I do this a couple of times during startup. So in case IsTrial() requires a network connection this could be the actual issue when there is only a bad connection available. But again, I couldn't find anything using Fiddler. The documentation (see here) for LicenseInformation does not mention whether a network connection is required or not.
Searching around I found that there is an updated interface available for both WP 8.1 SL and also W10M UWP.
var li = CurrentApp.LicenseInformation;
if (li.IsTrial) {
...
}
Its documentation clearly states that there is no network connection required for that (see here).
Even though the docs say that CurrentApp.LicenseInformation is also available on WP8 I also found some references that say that you only get a reliable answer for the IsTrial-question when using new LicenseInformation() (e.g. here).
Actual Questions
Is new LicenseInformation() required on WP8.1 SL, or can I use CurrentApp.LicenseInformation as well?
Does new LicenseInformation() require a network connection compared to CurrentApp.LicenseInformation?
How to get the number of (open) MongoDB connections with the C# driver (1.9.0 NuGet package)?
MongoDB documentations describes that db.serverStatus() should give iformation about the count of open and available connections but I can't find any function in the C# driver which represents this information.
(Documentation of db.serverStatus(): http://docs.mongodb.org/manual/reference/command/serverStatus/ )
I searched my fork of the driver for serverStatus, there's no results, so currently, I don't think this command is supported.
There's no associated jira (with serverStatus, at least) that i can find
Adding this functionality would be fairly trivial I would think
Edit
I wrote on the mongodb driver google group, and got this reply from Craig at MongoDB inc.
You can simply run:
MongoDatabase adminDb = ...;
adminDb.RunCommand("serverStatus");
I believe this needs to be run on the admin database.
I have a c# app which collects data(cpu, ram, hdd usages etc) from remote windows machines via WMI. But now I also need to monitor few linux boxes. Is there a way to get at least CPU and RAM utilization of linux machines from c# app running on windows box?
I managed to get metric stats from linux box. So as VirtualBlackFox mentioned - the standarized way is to use snmp for this purposes.
First step is to install snmp on linux. (I installed Ubuntu 12 on VM)
Here are the links which I used for installing snmp one and two.
Basically you need to install snmp daemon and configure for expose metrics and network visibility.
I think at this step you are free to use some snmp library to get data from snmp device, but I also tried to use WMI-SNMP bridge.
Step two: Setting up the WMI SNMP Environment
This is the list of steps you need to perform.
For me was enough to
Enable snmp feature in windows features
Create snmp folder in %windir%\system32\wbem\
Using this command Smi2smir /g ..\..\hostmib.mib > hostmib.mof for generating MOF files from MIB files
Adding SNMP MOF Files to the WMI Repository mofcomp hostmib.mof
After this I was able to see wmi classes and properties
Code examples
Using sharpsnmplib
using Lextm.SharpSnmpLib;
using Lextm.SharpSnmpLib.Messaging;
var result = Messenger.Get(
VersionCode.V1,
new IPEndPoint(IPAddress.Parse("172.10.206.108"), 161),
new OctetString("public"),
new List<Variable> { new Variable(new ObjectIdentifier("1.3.6.1.4.1.2021.4.6.0")) },
60000);
This one will return total ram used on the box. (btw, standart port for snmp is 161)
Using snmp-wmi bridge
string snmpClass = "SNMP_RFC1213_MIB_system";
string path = string.Format("\\\\.\\root\\snmp\\localhost:{0}=#", snmpClass);
var contextParams = new ManagementNamedValueCollection
{
{"AgentAddress", "172.10.206.108"}, // ip address of snmp device
{"AgentReadCommunity", "public"}
};
var options = new ObjectGetOptions(contextParams);
var objSys = new ManagementObject(new ManagementPath(path), options);
Console.WriteLine(objSys.Properties["sysDescr"].Value);
Console.ReadLine();
So there are at least two ways to get snmp data:
Using OID (Object Identifiers uniquely identify manged objects in a MIB hierarchy) as I shown in first example. And here is useful link. Also you can find OIDs in .mof files.
Using wmi-snmp bridge. So I used path like in second example, if it is not working for you, I think you can find correct one in WMI Explorer for example.
So this is pretty much for it. Don't know which approach is better or faster. Will try both and see, which is more suitable for my purposes.
I am out of idea why this is NOT working:
PrintServer printServer = new PrintServer("\\\\servername");
I am having issue with the PrintServer initialization. The above mentioned exception keep appearing even the printerServer path provided is a valid path. This is being said so as I am able to enumerate all the printers using printerServer.GetPrintQueues and foreach the printQueue to get the corresponding HostingPrintServer name.
EnumeratedPrintQueueTypes[] queueTypesArray = new EnumeratedPrintQueueTypes[]
{
EnumeratedPrintQueueTypes.Connections,
EnumeratedPrintQueueTypes.Local,
};
PrintQueueIndexedProperty[] indexPropertyArray = new PrintQueueIndexedProperty[]
{
PrintQueueIndexedProperty.Name
};
PrintServer printServer = new PrintServer();
PrintQueueCollection queueCollection = printServer.GetPrintQueues(indexPropertyArray, queueTypesArray);
foreach (PrintQueue pq in queueCollection)
{
if (pq.FullName == printerName)
{
this.printServerName = pq.HostingPrintServer.Name;
this.printerName = pq.Name;
}
}
I have also tried using the way this post suggested to get the DNS hostEntry but without any luck.
PrintServerException - "...name is invalid" even though I can access the path from windows
For your information, I am using Visual Studio 2010 running on Windows XP with two network printers connected. The printers are able to perform printing without any issue using PrintDocument and the printers are displayed on the PrintDialog as well.
Does anyone faced this issue before? If yes, may I know how do you resolve the issue?
Million thanks in advance.
EDIT:
Just tested with another "real" server printer, the above mentioned method is working fine. It is believed that Novell iPrint service which I am not sure how is the behaviour of it causing the issue. If anyone know more about the way to access Novell iPrint print server using C#, please feel free to share. I am currently still searching for the
solution.
hey i was facing similar issue, this is what i observed and made following changes, just try and let me know.
This issue was occuring due to windows feature/role "Print and Document service" is missing on the system. This role is required for managing multiple printers or print servers and migrating printers to and from other windows servers.
To add the role Go To Control Panel->Turn windows feature on or off->click on check box "Print and Document Service"->install.
See with network administrator for installing this rule if you unable to add it.
After adding the role you can able to create print server object and get the all the printqueues on respective server.
My application runs under CF 2.0 locally and i would like to know how to connect and send something to print in the embedded printer of a http://www.milliontech.com/home/content/view/195/95/'>Bluebird BIP-1300 device.
Ideally i would like an example in C#.
Thank you in advance.
Use bbpdaapi.dll (search by google)
and in c#
using Bluebird.BIP.Printer;
...
this.prn1 = new Bluebird.BIP.Printer.Printer();
if (!this.prn1.Open(0))
{
MessageBox.Show("Can not open Printer", "Printer problem");
}
this.prn1.PrintText("sdfgidfui", 0);
this.prn1.PrintBitmap(#"\My Documents\sample.bmp", 0);
if (this.prn1.WaitUntilPrintEnd() == 1)
{
MessageBox.Show("No paper in Printer", "Printer problem");
}
}
this.prn1.Close();
and etc..
I'm not familiar with this particular device, but in general, printers in this class require you to send RAW data, as they don't have Windows drivers.
This KB article outlines how to send data to the device using C#: whether this is useful for you depends on whether the unmanaged APIs used are available in the environment your CF app runs on.
In case the APIs are supported, what you need next are the correct escape codes for the device in order to get the on-paper results you want. These are usually well-documented in the printer manual.
If the Spooler API is not available, or you run into other issues that make this approach more trouble than it's worth, the third-party PrinterCE.NetCF SDK may also be worth looking into.