Reputation:
Hopefully this will be one of those simple answers that is so simple they are hard to find through search (as most of my programing problems are these days)
I am currently attempting to create a VB.Net script that pulls up information on installed printers. I am using Visual Studio 2010 SP1, and as my target program needs to run on older machines, is currently built using .Net 3.5.
Looking online, there are several methods on how to do this, one from http://www.dotnetcurry.com/ShowArticle.aspx?ID=148 uses the following code:
Dim oquery As System.Management.ObjectQuery = New System.Management.ObjectQuery("SELECT * FROM Win32_Printer")
Dim mosearcher As System.Management.ManagementObjectSearcher = New System.Management.ManagementObjectSearcher(oquery)
Dim moc As System.Management.ManagementObjectCollection = mosearcher.Get()
For Each mo As ManagementObject In moc
Dim pdc As System.Management.PropertyDataCollection = mo.Properties
For Each pd As System.Management.PropertyData In pdc
If CBool(mo("Network")) Then
cmbPrinters.Items.Add(mo(pd.Name))
End If
Next pd
Next mo
the code is supposed to use System.Management as you can see. However, after importing System.Management, Visual Studio throws an error and states that ObjectQuery, ManagementObjectSearcher, and ManagementObject are not defined.
a quick look at the MSDN forums shows that ObjectQuery is a class of .Net 4, 3.5, 3.0 and 2.
I figured the error might be because I didn't have the .Net 3.5 SDK installed, so I installed the .Net 3.5 SP1 SDK to no avail.
edit: just to make clear, I am importing System.Management at the top "Imports System.Management"
Upvotes: 0
Views: 1165
Reputation: 137198
Double check that your a reference to "System.Management" is correct. Make sure that the "System.Management.dll" is properly included and there's no warning triangle over the name.
MSDN page for System.Management.ObjectQuery
Upvotes: 2