Information about local network devices with vb

Apostolos Doudakmanis 101 Reputation points
2024-12-06T08:19:09.4633333+00:00

on my local network devices (e.g. network printer, network scanner), how can i get the path, ip, mac address and any other information i can use

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,760 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 86,406 Reputation points
    2024-12-06T10:06:13.1333333+00:00

    In the EnumDevices function I posted in your other question, you can add the other columns (you must add them too in DeviceInfo class and in the test to add devices (devices.Add(device), to check all columns)

    New keys for columns (that I have in Windows 10, command 'shell:NetworkPlacesFolder', then Display menu, Details, to choose columns (right-click on columns headers)) :

            Public Shared ReadOnly PKEY_NetworkLocation As New PROPERTYKEY(New Guid("28636aa6-953d-11d2-b5d6-00c04fd918d0"), 4)
            Public Shared ReadOnly PKEY_NetworkProvider As New PROPERTYKEY(New Guid("28636aa6-953d-11d2-b5d6-00c04fd918d0"), 31)
            Public Shared ReadOnly PKEY_Devices_IpAddress As New PROPERTYKEY(New Guid("656A3BB3-ECC0-43FD-8477-4AE0404A96CD"), 12297)
            Public Shared ReadOnly PKEY_Devices_PhysicalAddress As New PROPERTYKEY(New Guid("656A3BB3-ECC0-43FD-8477-4AE0404A96CD"), 12294)
            Public Shared ReadOnly PKEY_Computer_Workgroup As New PROPERTYKEY(New Guid("5cde9f0e-1de4-4453-96a9-56e8832efa3d"), 2)
    

    New variables for columns in the function :

                    Dim sIpAddress As String = Nothing
                    Dim vVariantIpAddress As Object = Nothing
                    Dim pkIpAddress As PROPERTYKEY = PROPERTYKEY.PKEY_Devices_IpAddress
                    hr = pNetworkFolder2.GetDetailsEx(pidlChild, pkIpAddress, vVariantIpAddress)
                    If (hr = HRESULT.S_OK) Then
                        If TypeOf vVariantIpAddress Is Array Then
                            Dim stringArray As String() = TryCast(vVariantIpAddress, String())
                            If stringArray IsNot Nothing Then
                                For Each str As String In stringArray
                                    If (sIpAddress = Nothing) Then sIpAddress = str Else sIpAddress += "; " + str
                                Next
                            End If
                        End If
                    End If
    
                    Dim sPhysicalAddress As String = Nothing
                    Dim vVariantPhysicalAddress As Object = Nothing
                    Dim pkPhysicalAddress As PROPERTYKEY = PROPERTYKEY.PKEY_Devices_PhysicalAddress
                    hr = pNetworkFolder2.GetDetailsEx(pidlChild, pkPhysicalAddress, vVariantPhysicalAddress)
                    If (hr = HRESULT.S_OK) Then
                        sPhysicalAddress = vVariantPhysicalAddress
                    End If
    
                    Dim sNetWorkProvider As String = Nothing
                    Dim vVariantNetWorkProvider As Object = Nothing
                    Dim pkNetWorkProvider As PROPERTYKEY = PROPERTYKEY.PKEY_NetworkProvider
                    hr = pNetworkFolder2.GetDetailsEx(pidlChild, pkNetWorkProvider, vVariantNetWorkProvider)
                    If (hr = HRESULT.S_OK) Then
                        sNetWorkProvider = vVariantNetWorkProvider
                    End If
    
                    Dim sComputerWorkgroup As String = Nothing
                    Dim vVariantComputerWorkgroup As Object = Nothing
                    Dim pkComputerWorkgroup As PROPERTYKEY = PROPERTYKEY.PKEY_Computer_Workgroup
                    hr = pNetworkFolder2.GetDetailsEx(pidlChild, pkComputerWorkgroup, vVariantComputerWorkgroup)
                    If (hr = HRESULT.S_OK) Then
                        sComputerWorkgroup = vVariantComputerWorkgroup
                    End If
    
                    Dim sNetWorkLocation As String = Nothing
                    Dim vVariantNetWorkLocation As Object = Nothing
                    Dim pkNetWorkLocation As PROPERTYKEY = PROPERTYKEY.PKEY_NetworkLocation
                    hr = pNetworkFolder2.GetDetailsEx(pidlChild, pkNetWorkLocation, vVariantNetWorkLocation)
                    If (hr = HRESULT.S_OK) Then
                        sNetWorkLocation = vVariantNetWorkLocation
                    End If
    
    
    1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Apostolos Doudakmanis 101 Reputation points
    2024-12-06T16:09:48.15+00:00

    detect all devices on the network except mobile phones (Android, iPhone)


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.