Using vb.net WinForms code, find what is blocking an app on Windows

Job ID: 36494463

Budget: $30 – $250 AUD

Following are 2 example codes generated by ChatGPT, but both have compile errors.
You must get either code to compile and run.
Also test it by locking a file with Smart Windows App Blocker (https://securityxploded.com/smart-windows-application-blocker.php#gsc.tab=0)


Code 1:
Imports System.Diagnostics
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim processName As String = "yourAppName.exe" ' Replace "yourAppName.exe" with the name of your app


Dim processList() As Process = Process.GetProcessesByName(processName)


If processList.Length > 0 Then
Dim process As Process = processList(0)


Dim blockingProcesses() As Process = process.GetProcessesBlockingThisProcess()


If blockingProcesses.Length > 0 Then
MessageBox.Show("The following processes are blocking " & processName & ": " & String.Join(", ", blockingProcesses.Select(Function(p) p.ProcessName)))
Else
MessageBox.Show(processName & " is not being blocked by any processes.")
End If
Else
MessageBox.Show(processName & " is not currently running.")
End If
End Sub
End Class
Code 2
Imports System.Diagnostics

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim processList As Process() = Process.GetProcesses()
Dim blockingProcesses As List(Of Process) = New List(Of Process)()

For Each process As Process In processList
Try
Dim modules As ProcessModuleCollection = process.Modules

For Each module As ProcessModule In modules
If module.FileName.Contains("your_application_name") Then
blockingProcesses.Add(process)
End If
Next
Catch ex As Exception
End Try
Next

If blockingProcesses.Count > 0 Then
Dim message As String = "The following process(es) are blocking your application:" + Environment.NewLine

For Each process As Process In blockingProcesses
message += process.ProcessName + " (PID: " + process.Id.ToString() + ")" + Environment.NewLine
Next

MessageBox.Show(message)
Else
MessageBox.Show("No processes are blocking your application.")
End If
End Sub
End Class

Regards,
Leigh
Related categories: Windows API VB.NET