|
-
Feb 15th, 2009, 06:36 AM
#1
Thread Starter
Junior Member
[2008] Convert code
I need to convert the following code to work in a visual studio 2008 windows form application, can anyone help? At the moment ObjectQuery, ManagementObjectSearcher, ManagementObject and ManagementObjectCollection are not valid.
Code:
Dim objectQuery As New ObjectQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId IS NOT NULL")
Dim searcher As New ManagementObjectSearcher(Scope, objectQuery)
Dim os As ManagementObject
Dim moColl As ManagementObjectCollection = searcher.Get()
Dim _list As String = ""
For Each os In moColl
Console.WriteLine(os("NetConnectionId"))
Next os
-
Feb 15th, 2009, 06:45 AM
#2
Re: [2008] Convert code
You'll have to import the System.Management namespace, or specify the full class path for those 4 classes.
-
Feb 15th, 2009, 07:07 AM
#3
Re: [2008] Convert code
For future reference, open the MSDN Library to the index and type in the class name, then click the class overview topic. It will give you the assembly (DLL) the class is defined in and the namespace it's a member of. You then just make sure you've referenced the assembly and imported the namespace. This will work for any and every type that in the .NET Framework.
Last edited by jmcilhinney; Feb 15th, 2009 at 07:12 AM.
-
Feb 15th, 2009, 09:26 AM
#4
Thread Starter
Junior Member
Re: [2008] Convert code
I have added:
Imports System.Management
But it is still telling me that the types are not defined?
I have also loaded this example code from Microsoft help files into a new class and get the same error:
Code:
Imports System
Imports System.Management
Public Class Class1
Public Overloads Shared Function Main(ByVal args() As String) As Integer
Dim p As New ManagementPath("Win32_Service.Name=""Alerter""")
Dim o As New ManagementObject(p)
'Now it can be used
Console.WriteLine(o("Name"))
Return 0
End Function
End Class
ManagementPath and ManagementObject are not defined?
-
Feb 15th, 2009, 12:25 PM
#5
Re: [2008] Convert code
You may need to add a reference to system.management as JMC mentioned in his post.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|