From: karim on

Onur Güzel
Thank you so much, you've been a great help. With the last code I
am getting 4 error that I can't figure out.

*Identifier expected (a blue line after "Dim searcher As New
ManagementObjectSearcher)

*A blue line under ManagementObject (type 'managementObject' is not defined.

*Name 'searcher' is not declared.

*Type 'managementException' is not defined...

Here is how I have the code:

Imports System.Management

Public Class Form1

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Try
Dim searcher As New ManagementObjectSearcher _("root\CIMV2",
"SELECT * FROM Win32_UserAccount Where Domain=""BLABLA""")
For Each queryObj As ManagementObject In searcher.Get()
MsgBox(queryObj.GetPropertyValue("Name").ToString)
Next
Catch err As ManagementException
MessageBox.Show(err.Message)
End Try
End Sub
End Class
..............................................................................

Greatly appreciate you help.
From: Onur Güzel on
On Jan 28, 7:01 am, karim <ka...(a)discussions.microsoft.com> wrote:
> Onur Güzel
>           Thank you so much, you've been a great help. With the last code I
> am getting 4 error that I can't figure out.
>
> *Identifier expected (a blue line after "Dim searcher As New
> ManagementObjectSearcher)
>
> *A blue line under ManagementObject (type 'managementObject' is not defined.
>
> *Name 'searcher' is not declared.
>
> *Type 'managementException' is not defined...
>
> Here is how I have the code:
>
> Imports System.Management
>
> Public Class Form1
>
>     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button2.Click
>         Try
>             Dim searcher As New ManagementObjectSearcher _("root\CIMV2",
> "SELECT * FROM Win32_UserAccount Where Domain=""BLABLA""")
>             For Each queryObj As ManagementObject In searcher..Get()
>                 MsgBox(queryObj.GetPropertyValue("Name").ToString)
>             Next
>         Catch err As ManagementException
>             MessageBox.Show(err.Message)
>         End Try
>     End Sub
> End Class
> ..............................................................................
>
> Greatly appreciate you help.

Make sure you have added reference to System.Management.dll. Plus, in
the message the underscore "_" appears in order to provide proper
message layout as a line breaker just for the sake a of smooth view,
but Google Groups seems don't allow users to write down the entire
page to post code. You can remove it ("_") and directly specify in
ManagementObjectSearcher constructor.

Or try this:

'---------------------------------------------
Imports System.Management

Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim searcher As New ManagementObjectSearcher _
("root\CIMV2", _
"SELECT * FROM Win32_UserAccount Where Domain=""BLA""")
For Each queryObj As ManagementObject In searcher.Get()
MsgBox(queryObj.GetPropertyValue("Name").ToString)
Next
Catch err As ManagementException
MessageBox.Show(err.Message)
End Try
End Sub

End Class
'---------------------------------------------

Hope i clarified.

Onur Güzel
kimiraikkonen85(a)hotm...com