如何将多个多个搜索过程集成到此代码中?不管有什么过程,如果有的话就发生了,没有其他事情发生了。在我的代码中发现存在几个过程。 Chrome,记事本或其他。不仅是一次处理(对于我来说就是Chrome)。
p = Process.GetProcesses.Where(Function(ps)
ps.ProcessName.ToLower.StartsWith("chrome")).ToArray Or
ProcessName.ToLower.StartsWith("note")).ToArray
'等等。
此P应该包含要查找的几个过程。我该怎么办?以及大写和小写字母的用法?
Private Sub CheckIfRunning()
Try
Dim p() As Process
p = Process.GetProcesses.Where(Function(ps) ps.ProcessName.ToLower.StartsWith("chrome")).ToArray Or ProcessName.ToLower.StartsWith("note")).ToArray
If p.Count > 0 Then
'Codul pentru redenumire Fisier
MydpText.Text = (My.Application.Info.DirectoryPath + ("\Keygen.txt"))
My.Computer.FileSystem.RenameFile(MydpText.Text, "Keygen.exe")
'Codul pentru rularea aplicației
Timer1.Enabled = True
Else
Timer1.Enabled = False
My.Computer.FileSystem.RenameFile(MydpText.Text, "Keygen.txt")
End If
Catch ex As Exception
End Try
End Sub
代码2:
Private Sub CheckIfRunning()
Dim processes() As Process
Dim instance As Process
processes = Process.GetProcesses
For Each instance In processes
If instance.ProcessName = "notepad" Then
MsgBox("")
End If
Next
End Sub
答案 0 :(得分:0)
要获得具有多个不同进程的数组,可以执行以下操作:
Try
Dim p() As Process
p = Process.GetProcesses.Where(Function(ps) ps.ProcessName.ToLower.StartsWith("chrome") Or ps.ProcessName.ToLower.StartsWith("note")).ToArray
If p.Count > 0 Then
Array.ForEach(p, Sub(process) Console.WriteLine("Process : {0} ({1})", process.ProcessName, process.Id))
Else
Console.WriteLine("No process found")
End If
Catch ex As Exception
MessageBox.Show(String.Format("An error occurred:{0}{0}{1}", vbCrLf, ex.Message), "Exception Thrown", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try