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
Related
I'm developing a desktop application for my company (it's just a prototype, actually) for bringing simple services to production department (tool and process instructions, presence records, product traceability, etc).
I'm using VB.net and wpf; some MS Access databases are the backend. It uses Access Database Engine 2016.
I have a simple function used to update database records, here's it:
Public Function UpdateDatabaseRecord(DatabaseNumber As Integer, tblName As String, SearchInColumn As String, SearchBy As String, UpdateColumn As String, UpdateTo As String) As Integer
Try
Using ServerConnection As New OleDbConnection(ConnectionSelector(DatabaseNumber))
Dim CommandString As String
If SearchInColumn <> "ID" Then
CommandString = "UPDATE [" & tblName & "] SET [" & UpdateColumn & "]=#UpdateColumn WHERE [" & SearchInColumn & "] = " & DQ & SearchBy & DQ
Else
CommandString = "UPDATE [" & tblName & "] SET [" & UpdateColumn & "]=#UpdateColumn WHERE [" & SearchInColumn & "] = " & SearchBy
End If
Dim CommandUpdate As New OleDbCommand(CommandString, ServerConnection) With {.CommandTimeout = 10000}
With CommandUpdate.Parameters
.AddWithValue("#UpdateColumn", UpdateTo)
End With
ServerConnection.Open()
CommandUpdate.ExecuteNonQuery()
ServerConnection.Close()
End Using
UpdateDatabaseRecord = 0
SetCentralTimeStamp(DatabaseNumber, tblName)
Catch ex As Exception
Msg(Reflection.MethodBase.GetCurrentMethod.Name & NewLine & ex.Message & NewLine & "Err. Number " & Err.Number, "Database Error", MessageBoxButton.OK, MessageBoxImage.Error)
UpdateDatabaseRecord = Err.Number
End Try
End Function
Sometimes the application uses this function in the main thread; sometimes it runs it from scheduled task (clocked by a forms.timer every two minutes). This tasks aren't obviously in the main thread, but the code has been used succesfully for a couple of months with computers directly connected to company network via LAN cable. Recently I tried my application on a laptop connected via wifi to the company network, and I get an exception that's crashing my app. I installed VS on that laptop to debug the code, and I found that an AccessViolationException is raised on line "CommandUpdate.ExecuteNonQuery".
I tried to google it but it seems that this exception shouldn't be raised from managed code.
The error occours only with laptop connected via wifi.
Also, another function reads data from the databases: sometimes I get the same error in it, in the line where the connection is being opened (connection.open).
What should I check?
Thanks in advance.
ps "ConnectionSelector" is a simple function which returns the appropriate ConnectionString based on database number.
EDIT 1 - The WiFi network is created plugging directly a LAN cable from the actual wired network, using a common wireless router. IP addresses are automatically assigned and the connection works, since the app is able to get data from databases.
I solved the problem myself and I'm posting here the solution I found: I hope it will help someone in the future.
I resolved simply enabling all OLEDB Services for the database connection. It looks like connection pooling really help stability and performance, especially when using a wifi network like I'm forced to do. If you want, Google "OLEDB Services" and look for enabling them all.
I have this code that find who has a file opened. The files are on network drives that use our old username as authenication. Our username use to be john.doe, it is now a number 12345. The code does not find a username. Is there something I'm overlooking or need to do to find out who has the file opened? Curious if and when we are on the actual new network that host the username 12345, that we will be able to find see the username 12345. The error message i do get is:
"The trust relationship between this workstation and the primary domain failed"
Public Shared Function GetFileOwner(ByVal strFileName)
Try
Dim objSD As Object = Nothing
Dim objWMIService = GetObject("winmgmts:")
Dim objFileSecuritySettings =
objWMIService.Get("Win32_LogicalFileSecuritySetting='" & strFileName & "'")
Dim intRetVal = objFileSecuritySettings.GetSecurityDescriptor(objSD)
If intRetVal = 0 Then
GetFileOwner = objSD.Owner.Name
Else
GetFileOwner = "Unknown"
End If
Catch ex As Exception
MsgBox("Error :" & Date.Today.ToString & " " & ex.Message)
GetFileOwner = "Unknown"
End Try
End Function
Do you know that this option is available on your server? You can easily do this..
Open the Computer Management snap-in on your file server (or connect to the server remotely from the management console running on your computer) and go to System Tools -> Shared Folders -> Open files. The list of files opened on the remote server is displayed on the right side of the window.
Many times i tried to access my server on the domain and it gave me that error, domains hate custom made apps :)
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("----------------------------------------")
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.
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.