1

我试图制作一个文件解锁器,它获取使用该文件的进程并将其杀死以使其能够被删除。当我的目标文件是 WMP 文件时没关系。但是当涉及到 dll 和 iso 时,我无法让它工作。我在这条线上遇到了问题:

用于获取进程名称。任何帮助表示赞赏。

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
4

1 回答 1

-2

我已经有了解决方案。只需添加 Try..Catch..

于 2012-11-30T11:11:18.007 回答