Confirm USB Device is Connected To Correct Port - vb.net

Good evening, I have a small challenge that I'm trying to get around. I have a user environment where all devices are 'built' using identical system images and identical hardware. It's a small point of sale environment. The software on the computers requires devices to be connected to particular USB other wise the devices will not work with the software. This presents a lot of issues as the cables aren't physically labelled.
I'm trying to create a small Visual Basic application which is able to check what device is connected to each USB port on the system. The program seems simple to me, but I've been having difficulty with the code for a few days. Is it possible to return the USB Port ID using the code below. I'm able to retrieve then DeviceID, but I now need to compare this with the USB ID to confirm it's in the correct port, how can I retrieve the USB Port ID/Name?
Dim sc As New ManagementScope("\\DESKTOP-BA9EEM9\root\cimv2")
Dim query As New ObjectQuery("Select * from Win32_USBHub")
Dim searcher As New ManagementObjectSearcher(sc, query)
Dim result As ManagementObjectCollection = searcher.Get()
For Each obj As ManagementObject In result
If obj("Description") IsNot Nothing Then
ListBox1.Items.Add("Description:" & vbTab + obj("Description").ToString())
End If
If obj("DeviceID") IsNot Nothing Then
ListBox1.Items.Add("DeviceID:" & vbTab + obj("DeviceID").ToString())
End If
If obj("PNPDeviceID") IsNot Nothing Then
ListBox1.Items.Add("PNPDeviceID:" & vbTab + obj("PNPDeviceID").ToString())
End If
ListBox1.Items.Add("----------------------------------------")

Related

Find all devices on local network

Looking for a faster way to find all devices connected to a network. Below is the code I tried. It is slow and does not pick up all devices. I have a few Raspberry Pi connected and the loop does not find them.
Dim i As Integer
Dim strIPAddress As String
Dim lstAddresses As System.Net.IPHostEntry
For i = 1 To 255
Try
strIPAddress = "192.168.33." & i
lstAddresses = System.Net.Dns.GetHostEntry(strIPAddress)
Console.WriteLine(strIPAddress & " " & lstAddresses.HostName)
Catch ex As Exception
End Try
Next i
You cab easily find out how many peoples are using your wifi. I found this great article:
How to List all devices info on your WLAN /router Programmatically in C#
It's in Csharp but you can easily convert it to Visual Basic using converter.telerik.com

vb.net USB Port Name/Description

I already acquired the code for Name of the modem. But I don't know how to use WMI because I can't really understand how does it works. For now, the code for it is so complicated.
Can you guys help me regarding to name my port? It's RFID Reader and it's USB Port. Look for the image as reference.
This image will show you that in Left Side < I got my COM 7 port in Modem but In right side > I got many option to pick, because my modem opens many port. I need to know how to name my other port(RFID COM PORT) so that I dont need to guess what is the right port for it.
Try
Dim searcher As New ManagementObjectSearcher( _
"root\cimv2", _
"SELECT * FROM Win32_SerialPort")
For Each queryObj As ManagementObject In searcher.Get()
MsgBox(queryObj("Name"))
enter code here
Next
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
So, I change the code, and I just want the system to message me what is the open port. But, unfortunately, My RFID (Profilic USB-to-Serial Comm Port (COM3) is not being shown.
Edit
This is the output messagebox, well as you can see guys, there's no profilic. Even though it's been plugged, and seen by Device Manager.
But If I change the code to Win32_PnPEntity it will show all peripherals, and etc. and eventually It will show the Image

TelnetExpect Reading Output from Stream in VB.NET

Good Morning,
I have been tasked with writing a program that locates the local port a MAC Address is registered to, and to do that I need to SSH and Telnet into Cisco devices and receive the output of the commands so I can parse it and decide what to do with the information.
So far I have the SSH connection and parsing done no problem thanks to Renci.SshNET. But I am having trouble with the Telnet, I set it up to use Telnetlib.dll and I know it works because I can do "show users" on the switch I'm connecting to and see that one of the vty lines are being occupied by my application. But in the application I'm writing all I get is the application freezing up, none of the buttons work, and I can't see the mouse when I hover over the window, so I'm guessing that the application isn't liking something at run-time.
The code I'm using, in VB.NET is:
Using client As TcpClient = New TcpClient(host, 23)
Dim tel As TelnetStream = New TelnetStream(client.GetStream)
Dim buff(client.ReceiveBufferSize) As Byte
Dim result As String
tel.SetRemoteMode(TelnetOption.Echo, False)
Dim exp As Expector = New Expector(tel)
exp.Expect("username: ")
exp.SendLine(username)
exp.Expect("password: ")
exp.SendLine(password)
exp.Expect(">")
tel.Read(buff, 0, buff.Length)
result = System.Text.Encoding.ASCII.GetString(buff)
MessageBox.Show(result)
End Using
Telnetlib.dll include the definitions for the Expector, SendLine, Expect, and TelnetStream.
I did some debugging and found that it freezes when it goes to execute the result = System.Text.Encoding.ASCII.GetString(buff)
command.
Thanks for any help.

Connect to an available wireless network using VB.NET

Using VB.NET how do I connect to an available wireless network. I have been able to list all the available networks.
Assuming you are wanting to control the Windows biult-in wifi stack, you should be able to do it with the WlanConnect Function. A signature is availeble at pinvoke.net.
MSDN has a list of the articles pertaining to wifi here.
The MSDN page does not say whether this is the case, but an application might need elevated permissions to use this API...
If you have the WLAN profile saved in your PC, this approach is simple.
Sub connectTo(ByVal name As String)
Dim p = "netsh.exe"
Dim sInfo As New ProcessStartInfo(p, "wlan connect " & name)
sInfo.CreateNoWindow = True
sInfo.WindowStyle = ProcessWindowStyle.Hidden
Process.Start(sInfo)
End Sub
'use the sub to connect to your AP. connectTo("myAP")
Otherwise, it is easier to use ManagedWifi or SimpleWifi dll libraries. Here is my code where I used SimpleWifi.dll to connect to a network with a passkey.

Get H/D Serial number (Not Volumn Serial Number) for IDE and SATA

How can I read the hard disk serial number for IDE and SATA drives in VB.NET?
(I don't want the volume serial number).
This info should be gathered both for XP and Vista if possible without administrative rights.
You can use WMI (Windows Management Instrumentation) like this:
Dim mos As New ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")
For Each mo As ManagementObject In mos.Get()
Dim serial As String = mo("SerialNumber").ToString()
Next
Although, I've read about cases in which no serial number is returned using WMI. Another way to accomplish this would be through Platform Invocation Services (PInvoke).
This article includes a download in which the author implements CreateFile() and DeviceIoControl() to extract drive information through Interop services in VB .NET.
To use either of the above outlined methods you will need ADMIN rights, a utility which seems to circumvent this can be found here. If your feeling adventurous the C++/Win32 source code is available for you to peruse. (Check out the function 'ReadPhysicalDriveInNTWithZeroRights()')
Public Function getHardDiskSerialNo()
Dim serial As String
Dim hd As New ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")
For Each dvs As ManagementObject In hd.Get()
serial = dvs("SerialNumber").ToString()
Next
Return serial
End Function
Here is the code to get HDD Serial Number
Dim HDD_Serial As String
Dim hdd As New ManagementObjectSearcher("select * from Win32_DiskDrive")
For Each hd In hdd.Get
HDD_Serial = hd("SerialNumber")
MsgBox(HDD_Serial)
Next
Hope it Helps.