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.Management
Paste in the code below:
----------------------------------------
Imports System.Management
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.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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.Diagnostics.DebuggerStepThrough()Private Sub
InitializeComponent()
Me.txtResults = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'txtResults
'
Me.txtResults.Location = New System.Drawing.Point(16, 16)
Me.txtResults.Multiline = True
Me.txtResults.Name = "txtResults"
Me.txtResults.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.txtResults.Size = New System.Drawing.Size(288, 192)
Me.txtResults.TabIndex = 0
Me.txtResults.Text = ""
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 224)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Get"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(232, 224)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 2
Me.Button2.Text = "Exit"
'
'Form1
'
Me.AutoScaleBaseSize = 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.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScree n
Me.Text = "Results"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strTemp As String
Try
Dim mos As New ManagementObjectSearcher("root\CIMV2", "SELECT *
FROM Win32_Product")
For Each mo As ManagementObject In mos.Get()
txtResults.Text += CType(mo("Caption"), String) &
ControlChars.CrLf
Next
Catch ex As ManagementException
MessageBox.Show("An error occurred", Me.Text)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Application.Exit()
End Sub
End Class
---------------------------------------------------
I hope this helps,
--
Newbie Coder
(It's just a name)
"shane" <az***@hotmail.comwrote in message
news:u9**************@TK2MSFTNGP02.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 ManagementObject in searcher.Get()
Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_Product instance")
Console.WriteLine("-----------------------------------")
Console.WriteLine("Caption: {0}", queryObj("Caption"))
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