WMI - shared remote printer on remote machine

F

farshad

The following WMI code only retrieves the list of local shared printers on a
target machine but NOT the list of shared REMOTE printers.
Any suggestions please?
string strWapiServer = "\\\\" + txtServerName.Text;
// Use the ObjectQuery to get the list of configured printers
System.Management.ObjectQuery oquery =
new System.Management.ObjectQuery("SELECT * FROM
Win32_Printer");

ConnectionOptions options = new ConnectionOptions();
ManagementScope myScope = new ManagementScope(strWapiServer +
"\\root\\cimv2", options);

System.Management.ManagementObjectSearcher mosearcher =
new System.Management.ManagementObjectSearcher(myScope,
oquery);

System.Management.ManagementObjectCollection moc =
mosearcher.Get();

foreach (ManagementObject mo in moc)
{
System.Management.PropertyDataCollection pdc = mo.Properties;
cboPrinters.Items.Add(pdc["DeviceID"].Value.ToString());
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top