Results 1 to 5 of 5

Thread: [2008] Convert code

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2009
    Posts
    21

    Smile [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

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Convert code

    You'll have to import the System.Management namespace, or specify the full class path for those 4 classes.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2009
    Posts
    21

    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?

  5. #5
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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
  •  



Click Here to Expand Forum to Full Width