检查二进制文件是否未损坏vb.net
嗨,我试着写一段代码来测试二进制文件是否损坏检查二进制文件是否未损坏vb.net,vb.net,Vb.net,嗨,我试着写一段代码来测试二进制文件是否损坏 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) Thr
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函数如果发现进程名,则返回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
对不起,我的英语不好有什么问题吗?你预计会发生什么?发生了什么事?你说的vb.net损坏是什么意思?我尝试运行一个.exe文件,等待2秒,检查是否有进程名正在工作,如果有列表框,则获取名称并终止进程,否则删除.exe并运行nexte.exe