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
您發佈的那一行代碼,不必爲獲取該進程而殺死它。你曾經嘗試和研究過什麼? – Styxxy
這只是我的代碼的一行。我使用這個http://mdetras.com/2011/06/11/get-processes-locking-a-file-in-vb-net/。 – Gunners98
我們需要您發佈的鏈接的TL版本,關於您的具體問題。 – Neolisk