我试图创建一个函数来搜索在参数中传递的进程,如果存在则返回true但它总是返回false
Public Function ps_running(ByVal name As String) As Boolean
For Each Proc As Process In Process.GetProcesses
If Proc.ProcessName.StartsWith(name) AndAlso (name.Length <> 0) Then
Return True
End If
Next
Return False
End Function
我确定它是基本的,我不知道但是我无法说出什么 谢谢
答案 0 :(得分:0)
检查一下:
Sub Main()
For Each Proc As Process In Process.GetProcesses
Console.WriteLine(Proc.ProcessName)
Next
Console.WriteLine()
Dim b As Boolean = ps_running("dwm")
Console.WriteLine(b)
Console.ReadLine()
End Sub
Public Function ps_running(ByVal name As String) As Boolean
If (String.IsNullOrEmpty(name)) Then Return False
For Each Proc As Process In Process.GetProcesses
If Proc.ProcessName.ToUpper.StartsWith(name.ToUpper) Then
Return True
End If
Next
Return False
End Function
使用完整测试编辑