WMI Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shane

    #1

    WMI Question

    I am trying to get values from a WMI Query in my textbox, txtResults I don't
    think I am understand what I need to do to move the value from the for each
    statement in the quary into the textbox, as the default implementation just
    provides for outputing information in the console.
    ' this wont work and when i try to replace the console writeline with some
    kind of txtresluts.text .,.....I either get an error or only the first set
    of values returned.
    For Each queryObj As ManagementObjec t in searcher.Get()

    Console.WriteLi ne("-----------------------------------")
    Console.WriteLi ne("Win32_Produ ct instance")
    Console.WriteLi ne("-----------------------------------")
    Console.WriteLi ne("Caption: {0}", queryObj("Capti on"))
    Next.

    I can write values in a class property that do not return multiple values,
    but am not able to get a return on anything but the first set of values.

    What Am I doing Wrong???

    thanks..Shane


  • Newbie Coder

    #2
    Re: WMI Question

    Shane,

    The code below does what you want but there is a pause getting the results
    in the textbox

    Start a new Windows Application
    Add reference to System.Manageme nt
    Paste in the code below:

    ----------------------------------------
    Imports System.Manageme nt

    Public Class Form1
    Inherits System.Windows. Forms.Form

    #Region " Windows Form Designer generated code "

    Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeCompo nent()

    'Add any initialization after the InitializeCompo nent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
    If Not (components Is Nothing) Then
    components.Disp ose()
    End If
    End If
    MyBase.Dispose( disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.Componen tModel.IContain er

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Friend WithEvents txtResults As System.Windows. Forms.TextBox
    Friend WithEvents Button1 As System.Windows. Forms.Button
    Friend WithEvents Button2 As System.Windows. Forms.Button
    <System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
    InitializeCompo nent()
    Me.txtResults = New System.Windows. Forms.TextBox
    Me.Button1 = New System.Windows. Forms.Button
    Me.Button2 = New System.Windows. Forms.Button
    Me.SuspendLayou t()
    '
    'txtResults
    '
    Me.txtResults.L ocation = New System.Drawing. Point(16, 16)
    Me.txtResults.M ultiline = True
    Me.txtResults.N ame = "txtResults "
    Me.txtResults.S crollBars = System.Windows. Forms.ScrollBar s.Vertical
    Me.txtResults.S ize = New System.Drawing. Size(288, 192)
    Me.txtResults.T abIndex = 0
    Me.txtResults.T ext = ""
    '
    'Button1
    '
    Me.Button1.Loca tion = New System.Drawing. Point(16, 224)
    Me.Button1.Name = "Button1"
    Me.Button1.TabI ndex = 1
    Me.Button1.Text = "Get"
    '
    'Button2
    '
    Me.Button2.Loca tion = New System.Drawing. Point(232, 224)
    Me.Button2.Name = "Button2"
    Me.Button2.TabI ndex = 2
    Me.Button2.Text = "Exit"
    '
    'Form1
    '
    Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
    Me.ClientSize = New System.Drawing. Size(322, 263)
    Me.Controls.Add (Me.Button2)
    Me.Controls.Add (Me.Button1)
    Me.Controls.Add (Me.txtResults)
    Me.FormBorderSt yle =
    System.Windows. Forms.FormBorde rStyle.FixedSin gle
    Me.MaximizeBox = False
    Me.MinimizeBox = False
    Me.Name = "Form1"
    Me.StartPositio n =
    System.Windows. Forms.FormStart Position.Center Screen
    Me.Text = "Results"
    Me.ResumeLayout (False)

    End Sub

    #End Region

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    Dim strTemp As String
    Try
    Dim mos As New ManagementObjec tSearcher("root \CIMV2", "SELECT *
    FROM Win32_Product")
    For Each mo As ManagementObjec t In mos.Get()
    txtResults.Text += CType(mo("Capti on"), String) &
    ControlChars.Cr Lf
    Next
    Catch ex As ManagementExcep tion
    MessageBox.Show ("An error occurred", Me.Text)
    End Try
    End Sub

    Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button2.Click
    Application.Exi t()
    End Sub
    End Class
    ---------------------------------------------------

    I hope this helps,

    --
    Newbie Coder
    (It's just a name)



    "shane" <azcpu@hotmail. comwrote in message
    news:u9S90dToHH A.4032@TK2MSFTN GP02.phx.gbl...
    I am trying to get values from a WMI Query in my textbox, txtResults I
    don't
    think I am understand what I need to do to move the value from the for
    each
    statement in the quary into the textbox, as the default implementation
    just
    provides for outputing information in the console.
    ' this wont work and when i try to replace the console writeline with some
    kind of txtresluts.text .,.....I either get an error or only the first set
    of values returned.
    For Each queryObj As ManagementObjec t in searcher.Get()
    >
    >
    Console.WriteLi ne("-----------------------------------")
    Console.WriteLi ne("Win32_Produ ct instance")
    >
    Console.WriteLi ne("-----------------------------------")
    Console.WriteLi ne("Caption: {0}", queryObj("Capti on"))
    Next.
    >
    I can write values in a class property that do not return multiple values,
    but am not able to get a return on anything but the first set of values.
    >
    What Am I doing Wrong???
    >
    thanks..Shane
    >
    >

    Comment

    • shane

      #3
      Re: WMI Question

      thanks,

      this code work great, but will not work for values of types other than
      string, If i want to add a value that is not of type, how would i format the
      value?

      I have tried a few variations and keep getting the following message
      "Additional information: Cast from type 'UInt64' to type 'Long' is not
      valid."

      here is the line that seems to be miscast.. txtresults.Text +=
      CType(mo("size" ), String) & ControlChars.Cr Lf

      thanks,

      shane





      Dim strTemp As String

      Try

      Dim mos As New ManagementObjec tSearcher("root \CIMV2", "SELECT * FROM
      Win32_LogicalDi sk")

      For Each mo As ManagementObjec t In mos.Get()

      txtResults.Text += CType(mo("size" ), String) & ControlChars.Cr Lf

      Next

      Catch ex As ManagementExcep tion

      MessageBox.Show ("An error occurred", Me.Text)

      End Try

      "Newbie Coder" <newbiecoder@sp ammeplease.comw rote in message
      news:eVMtX1XoHH A.4424@TK2MSFTN GP03.phx.gbl...
      Shane,
      >
      The code below does what you want but there is a pause getting the results
      in the textbox
      >
      Start a new Windows Application
      Add reference to System.Manageme nt
      Paste in the code below:
      >
      ----------------------------------------
      Imports System.Manageme nt
      >
      Public Class Form1
      Inherits System.Windows. Forms.Form
      >
      #Region " Windows Form Designer generated code "
      >
      Public Sub New()
      MyBase.New()
      >
      'This call is required by the Windows Form Designer.
      InitializeCompo nent()
      >
      'Add any initialization after the InitializeCompo nent() call
      >
      End Sub
      >
      'Form overrides dispose to clean up the component list.
      Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      If disposing Then
      If Not (components Is Nothing) Then
      components.Disp ose()
      End If
      End If
      MyBase.Dispose( disposing)
      End Sub
      >
      'Required by the Windows Form Designer
      Private components As System.Componen tModel.IContain er
      >
      'NOTE: The following procedure is required by the Windows Form Designer
      'It can be modified using the Windows Form Designer.
      'Do not modify it using the code editor.
      Friend WithEvents txtResults As System.Windows. Forms.TextBox
      Friend WithEvents Button1 As System.Windows. Forms.Button
      Friend WithEvents Button2 As System.Windows. Forms.Button
      <System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
      InitializeCompo nent()
      Me.txtResults = New System.Windows. Forms.TextBox
      Me.Button1 = New System.Windows. Forms.Button
      Me.Button2 = New System.Windows. Forms.Button
      Me.SuspendLayou t()
      '
      'txtResults
      '
      Me.txtResults.L ocation = New System.Drawing. Point(16, 16)
      Me.txtResults.M ultiline = True
      Me.txtResults.N ame = "txtResults "
      Me.txtResults.S crollBars = System.Windows. Forms.ScrollBar s.Vertical
      Me.txtResults.S ize = New System.Drawing. Size(288, 192)
      Me.txtResults.T abIndex = 0
      Me.txtResults.T ext = ""
      '
      'Button1
      '
      Me.Button1.Loca tion = New System.Drawing. Point(16, 224)
      Me.Button1.Name = "Button1"
      Me.Button1.TabI ndex = 1
      Me.Button1.Text = "Get"
      '
      'Button2
      '
      Me.Button2.Loca tion = New System.Drawing. Point(232, 224)
      Me.Button2.Name = "Button2"
      Me.Button2.TabI ndex = 2
      Me.Button2.Text = "Exit"
      '
      'Form1
      '
      Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
      Me.ClientSize = New System.Drawing. Size(322, 263)
      Me.Controls.Add (Me.Button2)
      Me.Controls.Add (Me.Button1)
      Me.Controls.Add (Me.txtResults)
      Me.FormBorderSt yle =
      System.Windows. Forms.FormBorde rStyle.FixedSin gle
      Me.MaximizeBox = False
      Me.MinimizeBox = False
      Me.Name = "Form1"
      Me.StartPositio n =
      System.Windows. Forms.FormStart Position.Center Screen
      Me.Text = "Results"
      Me.ResumeLayout (False)
      >
      End Sub
      >
      #End Region
      >
      Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
      System.EventArg s) Handles Button1.Click
      Dim strTemp As String
      Try
      Dim mos As New ManagementObjec tSearcher("root \CIMV2", "SELECT *
      FROM Win32_Product")
      For Each mo As ManagementObjec t In mos.Get()
      txtResults.Text += CType(mo("Capti on"), String) &
      ControlChars.Cr Lf
      Next
      Catch ex As ManagementExcep tion
      MessageBox.Show ("An error occurred", Me.Text)
      End Try
      End Sub
      >
      Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
      System.EventArg s) Handles Button2.Click
      Application.Exi t()
      End Sub
      End Class
      ---------------------------------------------------
      >
      I hope this helps,
      >
      --
      Newbie Coder
      (It's just a name)
      >
      >
      >
      "shane" <azcpu@hotmail. comwrote in message
      news:u9S90dToHH A.4032@TK2MSFTN GP02.phx.gbl...
      >I am trying to get values from a WMI Query in my textbox, txtResults I
      don't
      >think I am understand what I need to do to move the value from the for
      each
      >statement in the quary into the textbox, as the default implementation
      just
      >provides for outputing information in the console.
      >' this wont work and when i try to replace the console writeline with
      >some
      >kind of txtresluts.text .,.....I either get an error or only the first
      >set
      >of values returned.
      >For Each queryObj As ManagementObjec t in searcher.Get()
      >>
      >>
      Console.WriteLi ne("-----------------------------------")
      > Console.WriteLi ne("Win32_Produ ct instance")
      >>
      Console.WriteLi ne("-----------------------------------")
      > Console.WriteLi ne("Caption: {0}",
      >queryObj("Capt ion"))
      > Next.
      >>
      >I can write values in a class property that do not return multiple
      >values,
      >but am not able to get a return on anything but the first set of values.
      >>
      >What Am I doing Wrong???
      >>
      >thanks..Shan e
      >>
      >>
      >
      >

      Comment

      • Newbie Coder

        #4
        Re: WMI Question

        Shane,

        SIZE isn't part of 'Win32_Product' , hence the error:

        http://msdn2.microsoft.com/en-us/library/aa394378.aspx

        --
        Newbie Coder
        (It's just a name)



        "shane" <azcpu@hotmail. comwrote in message
        news:uTR6UqZoHH A.4516@TK2MSFTN GP05.phx.gbl...
        thanks,
        >
        this code work great, but will not work for values of types other than
        string, If i want to add a value that is not of type, how would i format
        the
        value?
        >
        I have tried a few variations and keep getting the following message
        "Additional information: Cast from type 'UInt64' to type 'Long' is not
        valid."
        >
        here is the line that seems to be miscast.. txtresults.Text +=
        CType(mo("size" ), String) & ControlChars.Cr Lf
        >
        thanks,
        >
        shane
        >
        >
        >
        >
        >
        Dim strTemp As String
        >
        Try
        >
        Dim mos As New ManagementObjec tSearcher("root \CIMV2", "SELECT * FROM
        Win32_LogicalDi sk")
        >
        For Each mo As ManagementObjec t In mos.Get()
        >
        txtResults.Text += CType(mo("size" ), String) & ControlChars.Cr Lf
        >
        Next
        >
        Catch ex As ManagementExcep tion
        >
        MessageBox.Show ("An error occurred", Me.Text)
        >
        End Try
        >
        "Newbie Coder" <newbiecoder@sp ammeplease.comw rote in message
        news:eVMtX1XoHH A.4424@TK2MSFTN GP03.phx.gbl...
        Shane,

        The code below does what you want but there is a pause getting the
        results
        in the textbox

        Start a new Windows Application
        Add reference to System.Manageme nt
        Paste in the code below:

        ----------------------------------------
        Imports System.Manageme nt

        Public Class Form1
        Inherits System.Windows. Forms.Form

        #Region " Windows Form Designer generated code "

        Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeCompo nent()

        'Add any initialization after the InitializeCompo nent() call

        End Sub

        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
        If Not (components Is Nothing) Then
        components.Disp ose()
        End If
        End If
        MyBase.Dispose( disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.Componen tModel.IContain er

        'NOTE: The following procedure is required by the Windows Form
        Designer
        'It can be modified using the Windows Form Designer.
        'Do not modify it using the code editor.
        Friend WithEvents txtResults As System.Windows. Forms.TextBox
        Friend WithEvents Button1 As System.Windows. Forms.Button
        Friend WithEvents Button2 As System.Windows. Forms.Button
        <System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
        InitializeCompo nent()
        Me.txtResults = New System.Windows. Forms.TextBox
        Me.Button1 = New System.Windows. Forms.Button
        Me.Button2 = New System.Windows. Forms.Button
        Me.SuspendLayou t()
        '
        'txtResults
        '
        Me.txtResults.L ocation = New System.Drawing. Point(16, 16)
        Me.txtResults.M ultiline = True
        Me.txtResults.N ame = "txtResults "
        Me.txtResults.S crollBars =
        System.Windows. Forms.ScrollBar s.Vertical
        Me.txtResults.S ize = New System.Drawing. Size(288, 192)
        Me.txtResults.T abIndex = 0
        Me.txtResults.T ext = ""
        '
        'Button1
        '
        Me.Button1.Loca tion = New System.Drawing. Point(16, 224)
        Me.Button1.Name = "Button1"
        Me.Button1.TabI ndex = 1
        Me.Button1.Text = "Get"
        '
        'Button2
        '
        Me.Button2.Loca tion = New System.Drawing. Point(232, 224)
        Me.Button2.Name = "Button2"
        Me.Button2.TabI ndex = 2
        Me.Button2.Text = "Exit"
        '
        'Form1
        '
        Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
        Me.ClientSize = New System.Drawing. Size(322, 263)
        Me.Controls.Add (Me.Button2)
        Me.Controls.Add (Me.Button1)
        Me.Controls.Add (Me.txtResults)
        Me.FormBorderSt yle =
        System.Windows. Forms.FormBorde rStyle.FixedSin gle
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.StartPositio n =
        System.Windows. Forms.FormStart Position.Center Screen
        Me.Text = "Results"
        Me.ResumeLayout (False)

        End Sub

        #End Region

        Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
        System.EventArg s) Handles Button1.Click
        Dim strTemp As String
        Try
        Dim mos As New ManagementObjec tSearcher("root \CIMV2", "SELECT
        *
        FROM Win32_Product")
        For Each mo As ManagementObjec t In mos.Get()
        txtResults.Text += CType(mo("Capti on"), String) &
        ControlChars.Cr Lf
        Next
        Catch ex As ManagementExcep tion
        MessageBox.Show ("An error occurred", Me.Text)
        End Try
        End Sub

        Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
        System.EventArg s) Handles Button2.Click
        Application.Exi t()
        End Sub
        End Class
        ---------------------------------------------------

        I hope this helps,

        --
        Newbie Coder
        (It's just a name)



        "shane" <azcpu@hotmail. comwrote in message
        news:u9S90dToHH A.4032@TK2MSFTN GP02.phx.gbl...
        I am trying to get values from a WMI Query in my textbox, txtResults I
        don't
        think I am understand what I need to do to move the value from the for
        each
        statement in the quary into the textbox, as the default implementation
        just
        provides for outputing information in the console.
        ' this wont work and when i try to replace the console writeline with
        some
        kind of txtresluts.text .,.....I either get an error or only the first
        set
        of values returned.
        For Each queryObj As ManagementObjec t in searcher.Get()
        >
        >
        Console.WriteLi ne("-----------------------------------")
        Console.WriteLi ne("Win32_Produ ct instance")
        >
        Console.WriteLi ne("-----------------------------------")
        Console.WriteLi ne("Caption: {0}",
        queryObj("Capti on"))
        Next.
        >
        I can write values in a class property that do not return multiple
        values,
        but am not able to get a return on anything but the first set of
        values.
        >
        What Am I doing Wrong???
        >
        thanks..Shane
        >
        >
        >
        >

        Comment

        • shane

          #5
          Re: WMI Question

          here is what I came up with...I can now pass in what area of the WMI inned
          to look at..thanks for your help :)

          Function WMI_TextBox_Wri ter(ByVal strRootWMI As String, ByVal strNameWMI As
          String, ByVal WMIname As String) 'byval strRootWMI As String ,byval
          strNameWMI As String, byval WMIname As String

          Dim strTemp As Int64

          'Dim test3 As String = m_strTPM

          Try

          'These Variables are for legacy implementation

          'this was so i can remove comments and set function not to take variables

          'Dim strRootWMI As String = "root\CIMV2 "

          'Dim strNameWMI As String = "SELECT * FROM Win32_LogicalDi sk"

          'Dim WMIname As String = "size"

          'this set the ManagementObjec tSearcher using 2 variables that are passed
          into the function

          Dim mos As New ManagementObjec tSearcher(strRo otWMI, strNameWMI)

          ' create a for each statment to loop through the ManagementObjec t

          For Each mo As ManagementObjec t In mos.Get()

          'strTemp is set to fist instance of ManagementObjec t

          '

          strTemp += System.Convert. ToInt64(mo(WMIn ame))

          m_strTPM += System.Convert. ToString(strTem p) & vbCrLf

          txtResults.Text &= "Disk Size = " & Me.propTextBox_ Writer() & vbCrLf

          Beep()



          Next

          Catch ex As ManagementExcep tion

          MessageBox.Show ("An error occurred", Me.Text)

          End Try

          End Function

          "Newbie Coder" <newbiecoder@sp ammeplease.comw rote in message
          news:%23emnxnco HHA.5052@TK2MSF TNGP04.phx.gbl. ..
          Shane,
          >
          SIZE isn't part of 'Win32_Product' , hence the error:
          >
          http://msdn2.microsoft.com/en-us/library/aa394378.aspx
          >
          --
          Newbie Coder
          (It's just a name)
          >
          >
          >
          "shane" <azcpu@hotmail. comwrote in message
          news:uTR6UqZoHH A.4516@TK2MSFTN GP05.phx.gbl...
          >thanks,
          >>
          >this code work great, but will not work for values of types other than
          >string, If i want to add a value that is not of type, how would i format
          the
          >value?
          >>
          >I have tried a few variations and keep getting the following message
          >"Additional information: Cast from type 'UInt64' to type 'Long' is not
          >valid."
          >>
          >here is the line that seems to be miscast.. txtresults.Text +=
          >CType(mo("size "), String) & ControlChars.Cr Lf
          >>
          >thanks,
          >>
          >shane
          >>
          >>
          >>
          >>
          >>
          >Dim strTemp As String
          >>
          >Try
          >>
          >Dim mos As New ManagementObjec tSearcher("root \CIMV2", "SELECT * FROM
          >Win32_LogicalD isk")
          >>
          >For Each mo As ManagementObjec t In mos.Get()
          >>
          >txtResults.Tex t += CType(mo("size" ), String) & ControlChars.Cr Lf
          >>
          >Next
          >>
          >Catch ex As ManagementExcep tion
          >>
          >MessageBox.Sho w("An error occurred", Me.Text)
          >>
          >End Try
          >>
          >"Newbie Coder" <newbiecoder@sp ammeplease.comw rote in message
          >news:eVMtX1XoH HA.4424@TK2MSFT NGP03.phx.gbl.. .
          Shane,
          >
          The code below does what you want but there is a pause getting the
          results
          in the textbox
          >
          Start a new Windows Application
          Add reference to System.Manageme nt
          Paste in the code below:
          >
          ----------------------------------------
          Imports System.Manageme nt
          >
          Public Class Form1
          Inherits System.Windows. Forms.Form
          >
          #Region " Windows Form Designer generated code "
          >
          Public Sub New()
          MyBase.New()
          >
          'This call is required by the Windows Form Designer.
          InitializeCompo nent()
          >
          'Add any initialization after the InitializeCompo nent() call
          >
          End Sub
          >
          'Form overrides dispose to clean up the component list.
          Protected Overloads Overrides Sub Dispose(ByVal disposing As
          Boolean)
          If disposing Then
          If Not (components Is Nothing) Then
          components.Disp ose()
          End If
          End If
          MyBase.Dispose( disposing)
          End Sub
          >
          'Required by the Windows Form Designer
          Private components As System.Componen tModel.IContain er
          >
          'NOTE: The following procedure is required by the Windows Form
          Designer
          'It can be modified using the Windows Form Designer.
          'Do not modify it using the code editor.
          Friend WithEvents txtResults As System.Windows. Forms.TextBox
          Friend WithEvents Button1 As System.Windows. Forms.Button
          Friend WithEvents Button2 As System.Windows. Forms.Button
          <System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
          InitializeCompo nent()
          Me.txtResults = New System.Windows. Forms.TextBox
          Me.Button1 = New System.Windows. Forms.Button
          Me.Button2 = New System.Windows. Forms.Button
          Me.SuspendLayou t()
          '
          'txtResults
          '
          Me.txtResults.L ocation = New System.Drawing. Point(16, 16)
          Me.txtResults.M ultiline = True
          Me.txtResults.N ame = "txtResults "
          Me.txtResults.S crollBars =
          System.Windows. Forms.ScrollBar s.Vertical
          Me.txtResults.S ize = New System.Drawing. Size(288, 192)
          Me.txtResults.T abIndex = 0
          Me.txtResults.T ext = ""
          '
          'Button1
          '
          Me.Button1.Loca tion = New System.Drawing. Point(16, 224)
          Me.Button1.Name = "Button1"
          Me.Button1.TabI ndex = 1
          Me.Button1.Text = "Get"
          '
          'Button2
          '
          Me.Button2.Loca tion = New System.Drawing. Point(232, 224)
          Me.Button2.Name = "Button2"
          Me.Button2.TabI ndex = 2
          Me.Button2.Text = "Exit"
          '
          'Form1
          '
          Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
          Me.ClientSize = New System.Drawing. Size(322, 263)
          Me.Controls.Add (Me.Button2)
          Me.Controls.Add (Me.Button1)
          Me.Controls.Add (Me.txtResults)
          Me.FormBorderSt yle =
          System.Windows. Forms.FormBorde rStyle.FixedSin gle
          Me.MaximizeBox = False
          Me.MinimizeBox = False
          Me.Name = "Form1"
          Me.StartPositio n =
          System.Windows. Forms.FormStart Position.Center Screen
          Me.Text = "Results"
          Me.ResumeLayout (False)
          >
          End Sub
          >
          #End Region
          >
          Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
          System.EventArg s) Handles Button1.Click
          Dim strTemp As String
          Try
          Dim mos As New ManagementObjec tSearcher("root \CIMV2",
          "SELECT
          *
          FROM Win32_Product")
          For Each mo As ManagementObjec t In mos.Get()
          txtResults.Text += CType(mo("Capti on"), String) &
          ControlChars.Cr Lf
          Next
          Catch ex As ManagementExcep tion
          MessageBox.Show ("An error occurred", Me.Text)
          End Try
          End Sub
          >
          Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
          System.EventArg s) Handles Button2.Click
          Application.Exi t()
          End Sub
          End Class
          ---------------------------------------------------
          >
          I hope this helps,
          >
          --
          Newbie Coder
          (It's just a name)
          >
          >
          >
          "shane" <azcpu@hotmail. comwrote in message
          news:u9S90dToHH A.4032@TK2MSFTN GP02.phx.gbl...
          >I am trying to get values from a WMI Query in my textbox, txtResults I
          don't
          >think I am understand what I need to do to move the value from the for
          each
          >statement in the quary into the textbox, as the default implementation
          just
          >provides for outputing information in the console.
          >' this wont work and when i try to replace the console writeline with
          >some
          >kind of txtresluts.text .,.....I either get an error or only the first
          >set
          >of values returned.
          >For Each queryObj As ManagementObjec t in searcher.Get()
          >>
          >>
          Console.WriteLi ne("-----------------------------------")
          > Console.WriteLi ne("Win32_Produ ct instance")
          >>
          Console.WriteLi ne("-----------------------------------")
          > Console.WriteLi ne("Caption: {0}",
          >queryObj("Capt ion"))
          > Next.
          >>
          >I can write values in a class property that do not return multiple
          >values,
          >but am not able to get a return on anything but the first set of
          values.
          >>
          >What Am I doing Wrong???
          >>
          >thanks..Shan e
          >>
          >>
          >
          >
          >>
          >>
          >
          >

          Comment

          Working...