您好我尝试编写代码来测试二进制文件是否已损坏
For i As Integer = 0 To ListBox1.Items.Count - 1
ListBox1.SetSelected(i, True)
Dim name As String = ListBox1.Items.Item(i).ToString
Try
Process.Start(name)
Threading.Thread.Sleep(WaitingTb.Text)
If Not IsProcessRunning(NameTb.Text) Then
MsgBox(name)
My.Computer.FileSystem.DeleteFile(ListBox1.Items.Item(i).ToString)
ListBox1.Items.RemoveAt(i)
ListBox1.Items.Insert(i, name & " : Deleted !")
ElseIf IsProcessRunning(NameTb.Text) Then
MsgBox(name)
ListBox1.Items.RemoveAt(i)
ListBox1.Items.Insert(i, name & " : Ok !")
End If
Process.GetCurrentProcess.Kill()
Catch
End Try
Next
End Sub
IsProcessRunning函数如果找到proccess name,则返回true,否则返回false
Public Function IsProcessRunning(name As String) As Boolean
'here we're going to get a list of all running processes on
'the computer
For Each clsProcess As Process In Process.GetProcesses()
If clsProcess.ProcessName.StartsWith(name) Then
'process found so it's running so return true
clsProcess.Kill()
Return True
End If
Next
'process not found, return false
Return False
End Function
抱歉我的英文不好