I was trying to make a file unlocker which get process which using the file and get it killed to make it able to be deleted. It was okay when my targeted file is a WMP file. But I can’t get it work when it comes to dll and iso. I got the problem on this line:
Which is used to get the process name. Any help is appreciated.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnShow.Click
Dim files As New List(Of String)
files.Add(OpenFileDialog1.FileName)
Dim Processes As List(Of Process) = Util.GetProcessesUsingFiles(files)
RichTextBox1.AppendText(vbCrLf & "Processes that using the file is:")
For Each p As Process In Processes
TextBox1.Text = (Path.GetFileName(p.MainModule.FileName))
TextBox1.Text = TextBox1.Text.Replace(".exe", "")
Next
Timer1.Start()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnKill.Click
If TextBox1.Text = ("Nothing") Then
MsgBox("No proccess is using that file.")
ElseIf MsgBox("Proccess(es) killed") Then
End If
For Each p As Process In System.Diagnostics.Process.GetProcessesByName(Path.GetFileName(TextBox1.Text))
Try
p.Kill()
' possibly with a timeout
p.WaitForExit()
' process was terminating or can't be terminated - deal with it
Catch winException As Win32Exception
' process has already exited - might be able to let this one go
Catch invalidException As InvalidOperationException
End Try
Next
I’ve already got the solution. Just add Try..Catch..