Network logged in users

  • Thread starter Thread starter karim
  • Start date Start date
K

karim

Hi All,
Is there a way in vb to find all logged in users on a network? I know
using cmd, you can type >>nbtstat -a [MachineName]<< and it would show how's
logged on. so would we be able to do something like that using vb? and would
we be able to view all logged in users without typing the machine name?

Thanks for the help.
 
Hi All,
     Is there a way in vb to find all logged in users on a network?I know
using cmd, you can type >>nbtstat -a [MachineName]<< and it would show how's
logged on. so would we be able to do something like that using vb? and would
we be able to view all logged in users without typing the machine name?

Thanks for the help.

You can also try "net view" command from command prompt and redirect
stdout to your program as follows:

' -------------------------------------------
' Set start information.
Dim start_info As New ProcessStartInfo("cmd.exe", "/c net view")
start_info.UseShellExecute = False
start_info.CreateNoWindow = True
start_info.RedirectStandardOutput = True
start_info.RedirectStandardError = True

' Make the process and set its start information.
Dim proc As New Process()
proc.StartInfo = start_info

' Start the process.
proc.Start()

' Attach to stdout and stderr.
Dim std_out As IO.StreamReader = proc.StandardOutput()


' Display the results in a textbox
TextBox1.Text = std_out.ReadToEnd()


' Clean up.
std_out.Close()

proc.Close()

' -------------------------------------------

HTH,

Onur Güzel
 
Thank you very much. Works great.

Onur Güzel said:
Hi All,
Is there a way in vb to find all logged in users on a network? I know
using cmd, you can type >>nbtstat -a [MachineName]<< and it would show how's
logged on. so would we be able to do something like that using vb? and would
we be able to view all logged in users without typing the machine name?

Thanks for the help.

You can also try "net view" command from command prompt and redirect
stdout to your program as follows:

' -------------------------------------------
' Set start information.
Dim start_info As New ProcessStartInfo("cmd.exe", "/c net view")
start_info.UseShellExecute = False
start_info.CreateNoWindow = True
start_info.RedirectStandardOutput = True
start_info.RedirectStandardError = True

' Make the process and set its start information.
Dim proc As New Process()
proc.StartInfo = start_info

' Start the process.
proc.Start()

' Attach to stdout and stderr.
Dim std_out As IO.StreamReader = proc.StandardOutput()


' Display the results in a textbox
TextBox1.Text = std_out.ReadToEnd()


' Clean up.
std_out.Close()

proc.Close()

' -------------------------------------------

HTH,

Onur Güzel
.
 
But is there a way to view the logged on users on these clients?

Thank you...

Well, you can use WMI for a in-depth information. For example,
assuming your domain name is "blabla": you can get them using: (Add
reference to System.Management.dll)

'----------------------------------------------------
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

'----------------------------------------------------

HTH,

Onur Güzel
 
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.
 
Onur Güzel
          Thank you so much, you've been a great help. With thelast 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
[email protected]
 
Back
Top