Solved

Get remote pc mac address with vb.net

Posted on 2011-03-24
10
2,406 Views
Last Modified: 2012-05-11
Hi,
I'm working on a local application that retrieve a network card physical address. Here is my code:

Private Sub frmRemoteMacAddress_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim theNetworkInterfaces() As System.Net.NetworkInformation.NetworkInterface = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()

        For Each currentInterface As System.Net.NetworkInformation.NetworkInterface In theNetworkInterfaces

            If currentInterface.OperationalStatus = Net.NetworkInformation.OperationalStatus.Up And currentInterface.NetworkInterfaceType.ToString() = "Ethernet" Then

 lblRequestedMacAddress.Text = currentInterface.GetPhysicalAddress().ToString()
                    ' lblNicModel.Text = currentInterface.Description.ToString()
                End If
        Next
    End Sub

Therefor, this code retrieve only the local mac address.
Can anyone correct me please?
Thanks.
0
Comment
Question by:hamda000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
10 Comments
 

Expert Comment

by:Casirus
ID: 35214110
i found a few things like this before here is a code that gets it with WMI

to use this code you need to import System.Management and System.Management.Instrumentation namespaces

what it does is sends a request to a remote network computer to get the info

if its over the internet your wanting to do this then i would need to do some more looking

let me know if this helps

D.L.H.

Dim tm As New ManagementScope("\\" & ComputerName & "\root\cimv2")
        Dim tq as new string = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 1"

        Dim toq As New ObjectQuery(tq)

        Dim ts As New ManagementObjectSearcher(tm, toq)
        Dim trc As ManagementObjectCollection = ts.get()

        For Each cr As ManagementObject In trc
            MessageBox.Show(cr("MacAddress").ToString())
        Next

Open in new window

0
 

Author Comment

by:hamda000
ID: 35214378
Hi,

Thanks for the answer.
first the following statement has error:
Dim tq as new string = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 1"
The error is: end of statement expected.
Dim toq As New ObjectQuery(tq):
Error: tq is not declared.
We should may be write it this way:
Dim tq as new string( "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 1")
NO error

Second error in this line:
For Each cr As ManagementObject In trc
trc is underlined and have this statement:
Expression is of type 'RemoteComputerInfos.ManagementObjectCollection' which is not collection type.

Please take note that RemoteComputerInfos is the name of my application (Solution).

Thanks for correcting or submitting new items. I'm still working on.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35217025
Have you added

Imports System.Management

at the top and added reference to it as well?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:hamda000
ID: 35219654
Yes I did.
0
 

Expert Comment

by:Casirus
ID: 35239581
ahh ok sorry for taking so long but here is the way to fix it use the following edited code and follow the instructions at the bottom

 Dim tm As New ManagementScope("\\" & ComputerName & "\root\cimv2")
        Dim tq As String = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 1"
        Dim toq As New ObjectQuery(tq)

        Dim ts As New ManagementObjectSearcher(tm, toq)
        Dim trc As ManagementObjectCollection = ts.get()

        For Each cr As ManagementObject In trc
            MessageBox.Show(cr("MacAddress").ToString())
        Next

right click on references in solution explorer go to add reference and add System.Management.dll and  System.Management.Instrumentation.dll into the project.

and then try again :)
0
 

Author Comment

by:hamda000
ID: 35243261
Thank you.

Therefore I right click or double click on the My project (I am on VS 2010), I'm on the references tab, I choose the .com where are stored the .dll files and I click on Add but in the references list there are no System.Management.dll or System.Management.Instrumentation.dll

Sorry and thanks anyway
0
 

Expert Comment

by:Casirus
ID: 35280311
for the affore mentioned dlls are located in .NET not .COM

sorry for not pointing this out to start

DLH
0
 

Accepted Solution

by:
hamda000 earned 0 total points
ID: 35309147
Hi Casirus and thanks for ur help. It is not working. here is my whole code:


Imports System
Imports System.Management
Imports System.Management.Instrumentation
Imports System.Windows.Forms



Public Class frmRemoteComputerInfos


    Dim computerName As String
    Private Sub frmRemoteComputerInfos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblTodayDate.Text = Today

        computerName = InputBox("Tapez le nom de l'ordinateur auquel vous voulez vous connecter...", "Nom de l'ordinateur...")
        lblComputerName.Text = computerName.ToUpper
        lblRequestedIpAddress.Text = GetRemoteIPAddress()
    End Sub


    Function GetRemoteIPAddress()
        Dim ipentry As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(computerName)
        Dim strIPAddress As String = ""
        For i As Integer = 0 To ipentry.AddressList.Count - 1
            strIPAddress = System.Net.Dns.GetHostEntry(computerName).AddressList(i).ToString()
        Next
        Return strIPAddress
    End Function


    Private Sub GetRemoteMacAddress()
        Dim tm As New ManagementScope(computerName)
        Dim tq As String = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 1"
        Dim toq As New ObjectQuery(tq)

        Dim ts As New ManagementObjectSearcher(tm, toq)
        Dim trc As ManagementObjectCollection = ts.get()

        For Each ma As ManagementObject In trc
            MessageBox.Show(ma("MacAddress").ToString())
        Next

         End Sub

   
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Timer1.Start()
        lblChrono.Text = lblChrono.Text - 1
        If lblChrono.Text = "0" Then
            Timer1.Stop()
            Console.Beep()
            Me.Close()
        End If
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub


End Class

Open in new window

0
 

Author Comment

by:hamda000
ID: 35361250
HI everyone,

Sorry but all solutions displayed are did not fix my project. Please find attached a .sln file including my project. Some words are in french but I know you undrstand. If you need more files just let me know or tell me how I can upload the whole project.

Thanks.
Remote-Computer-Infos.vb
0
 

Author Closing Comment

by:hamda000
ID: 35814179
thanks.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question