Discussion:
Get a list of printers
(too old to reply)
Paul S
2007-04-10 08:24:01 UTC
Permalink
I need to get a list of printers in my C# application running on a server
including paper size, papaer source, driver name etc.

Do I use WMI or .. ?
--
Paul S
Newbie Coder
2007-05-12 01:09:36 UTC
Permalink
Paul,

This code gets a list of local printers:

using System;
using System.Management;
using System.Windows.Forms;

namespace WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Printer");

foreach (ManagementObject queryObj in searcher.Get())
{

Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_Printer instance");

Console.WriteLine("-----------------------------------");
Console.WriteLine("Name: {0}", queryObj["Name"]);
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI
data: " + e.Message);
}
}
}
}

This are scrips that pull out printers fron AD, but you will need to convert
it:

http://www.microsoft.com/technet/scriptcenter/guide/sas_prn_wize.mspx?mfr=true

Sorry that I cannot be of any more help
--
Newbie Coder
(It's just a name)
Post by Paul S
I need to get a list of printers in my C# application running on a server
including paper size, papaer source, driver name etc.
Do I use WMI or .. ?
--
Paul S
Paul S
2007-05-14 08:38:02 UTC
Permalink
I need to get the printers prefixed with fx. 'biz' - how do I change my
select. I have tried with sql syntax but then the select returns nothing
--
Paul S
Post by Newbie Coder
Paul,
using System;
using System.Management;
using System.Windows.Forms;
namespace WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Printer");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_Printer instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Name: {0}", queryObj["Name"]);
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI
data: " + e.Message);
}
}
}
}
This are scrips that pull out printers fron AD, but you will need to convert
http://www.microsoft.com/technet/scriptcenter/guide/sas_prn_wize.mspx?mfr=true
Sorry that I cannot be of any more help
--
Newbie Coder
(It's just a name)
Post by Paul S
I need to get a list of printers in my C# application running on a server
including paper size, papaer source, driver name etc.
Do I use WMI or .. ?
--
Paul S
Newbie Coder
2007-05-24 19:18:49 UTC
Permalink
Paul,

"Select * from Win32_Printer Where DeviceID = 'biz'")
--
Newbie Coder
(It's just a name)
Post by Paul S
I need to get the printers prefixed with fx. 'biz' - how do I change my
select. I have tried with sql syntax but then the select returns nothing
--
Paul S
Post by Newbie Coder
Paul,
using System;
using System.Management;
using System.Windows.Forms;
namespace WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Printer");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_Printer instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Name: {0}", queryObj["Name"]);
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI
data: " + e.Message);
}
}
}
}
This are scrips that pull out printers fron AD, but you will need to convert
http://www.microsoft.com/technet/scriptcenter/guide/sas_prn_wize.mspx?mfr=true
Post by Paul S
Post by Newbie Coder
Sorry that I cannot be of any more help
--
Newbie Coder
(It's just a name)
Post by Paul S
I need to get a list of printers in my C# application running on a server
including paper size, papaer source, driver name etc.
Do I use WMI or .. ?
--
Paul S
Paul S
2007-05-25 11:10:00 UTC
Permalink
Sorry - I needed to be more precise
It's the ShareName that's is prefixed with ex. 'biz'

Select * from Win32_Printer Where ShareName like 'biz%'")

it failed but now it works - I don't know what the problem was.

Still I need to select only local or network printers - I have tried with
the attribute field but without success.
--
Paul S
Post by Newbie Coder
Paul,
"Select * from Win32_Printer Where DeviceID = 'biz'")
--
Newbie Coder
(It's just a name)
Post by Paul S
I need to get the printers prefixed with fx. 'biz' - how do I change my
select. I have tried with sql syntax but then the select returns nothing
--
Paul S
Post by Newbie Coder
Paul,
using System;
using System.Management;
using System.Windows.Forms;
namespace WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Printer");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_Printer instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Name: {0}", queryObj["Name"]);
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for
WMI
Post by Paul S
Post by Newbie Coder
data: " + e.Message);
}
}
}
}
This are scrips that pull out printers fron AD, but you will need to
convert
http://www.microsoft.com/technet/scriptcenter/guide/sas_prn_wize.mspx?mfr=true
Post by Paul S
Post by Newbie Coder
Sorry that I cannot be of any more help
--
Newbie Coder
(It's just a name)
Post by Paul S
I need to get a list of printers in my C# application running on a
server
Post by Paul S
Post by Newbie Coder
Post by Paul S
including paper size, papaer source, driver name etc.
Do I use WMI or .. ?
--
Paul S
Loading...