Please any one help me to get all network printers.
I get all printers installed in the local machine using "System.Drawing.Printing.PrinterSettings.InstalledPrinters".
But I can't get the printers which are in the Network.
I try with "ManagementObjectSearcher" but I can't access this class.
I think it does not support in framework 4.0.
I'm using ASP.NET 4.0, C#. Any help will be greatly appreciated.
Thanks
Singaravelu.R.
if you cannot find/reference the ManagementObjectSearcher Class probably is because you did not add the proper reference to: System.Management.dll to your C# project. Surely it is supported also by .NET 4.
as you can see in this question: ManagementObjectSearcher select network printers? you can find all network printers in this way:
var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Printer");
var results = searcher.Get();
IList<ManagementBaseObject> printers = new List<ManagementBaseObject>();
foreach (var printer in results) {
if ((bool)printer["Network"]) {
printers.Add(printer);
}
}
Related
I have the following instructions in my code.
ManagementObjectSearcher usersSearcher = new ManagementObjectSearcher(#"SELECT * FROM Win32_UserAccount");
ManagementObjectCollection users = usersSearcher.Get();
It works fine on most machines. But in some cases the result (users) is empty. I failed to determine the reason. all three machine where it had happened are Windows 7 (Ultimate, Professional, Home Basic).
Is there any special conditions that causes this query to fail?
Thanks in advance.
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.
As noted, I'm on a Windows 8 machine using Visual Studio 2012.
I need to map/unmap network drives as well as get a list of all of the currently mapped drives.
To map/unmap I'm using WNetAddConnection2A and WNetCancelConnection2A, respectively, via PInvoke.
To get a list of the currently mapped drives, I'm currently using WMI and querying Win32_MappedLogicalDisk.
using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_MappedLogicalDisk"))
{
foreach (ManagementObject queryObj in searcher.Get())
{
}
}
The interesting bit is that the returned "mapped" drives from WMI do not show in the left panel of File Explorer under "Computer." The returned "mapped" drives also do not show using the "net use" command. I can map a drive via WNetAddConnection2A and it will be returned through the Win32_MappedLogicalDisk query but it will not show in File Explorer.
Additionally, I can manually map a drive via File Explorer and the mapped drive will show using "net use" but will not be returned using WMI to query Win32_MappedLogicalDisk.
File Explorer / "net use" don't seem to be talking to the same sources as WNetAddConnection2A / WMI.
I've tested this same code on Windows 7 without any issues.
Any help would be much appreciated. Thanks
Try the Win32_LogicalDisk WMI class and the DriveType property, (The value 4 indicates a Network Drive).
Select * From Win32_LogicalDisk Where DriveType = 4
Is there any way (in C#, using WMI classes) to find out that how many times a particular software has been installed and uninstalled?
I want to run it on remote computer. I am getting software list by following code:
ManagementScope scope = new ManagementScope(#"\\" + ipAddress + #"\root\cimv2");
ObjectQuery query = new ObjectQuery("Select * from Win32_Product");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
Console.Write(m["Caption"]+"\t");
Console.WriteLine(m["installDate"]);
}
Normally not.
When a program will be uninstalled every bit of the program should be removed from the machine like it was never their. Unfortunately nearly every program doesn't make a perfect job at this point leaving some artifacts on the machine.
Nevertheless the desired behavior is that after a uninstall everything is gone (including some kind of counter) so that it is only possible to check if a program is currently installed or not.
On the other site nothing permits a program to save somewhere some counter (e.g. registry) which will increased everytime a installation is started, but that's something specific for each program and no common mechanism exists where this counter should reside.
I use following c# code to get processor information. The Management class is null if I run my application on a virtual machine. I use Oracle VM VirtualBox as my virtual pc (Windows XP SP3)
System.Management.ManagementClass Management = new System.Management.ManagementClass("Win32_Processor");
Does anyone has experience about using such code and has problems in virtual machines.
Oracle VirtualBox does not provide such information.
Here is the related ticket.
https://www.virtualbox.org/ticket/9046
Are you using GetInstances?
System.Management.ManagementClass ManagementClass1 = new System.Management.ManagementClass("Win32_Processor");
System.Management.ManagementObjectCollection ManagementObjectCollection1 = ManagementClass1.GetInstances();
foreach (System.Management.ManagementObject managementobject in ManagementObjectCollection1) {
Console.Out.WriteLine(managementobject.Properties["Name"].Value);
}
Console.In.ReadLine();