VB怎样检查某个进程已运行几个
我想编一个vb程序,让它启动后检测自己运行了几个,如果运行了超过两个,就把自己关闭,我想让自己的程序最多同时运行两个。...
我想编一个vb程序,让它启动后检测自己运行了几个,如果运行了超过两个,就把自己关闭,我想让自己的程序最多同时运行两个。
展开
1个回答
展开全部
Option Explicit
Private Sub Form_Load()
MsgBox getInstanceCount("notepad.exe")
End Sub
'得到所有进程名为proName的个数
Private Function getInstanceCount(ByVal proName As String) As Integer
Dim objWMIService As Object
Dim colProcessList As Object
Dim objProcess As Object
Dim objProType As Object
Dim strResult As String
Dim strTmp As String
Set objWMIService = GetObject("winmgmts:" & "{impersonationlevel=impersonate}!\\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name='" & proName & "'")
getInstanceCount = colProcessList.Count
End Function
Private Sub Form_Load()
MsgBox getInstanceCount("notepad.exe")
End Sub
'得到所有进程名为proName的个数
Private Function getInstanceCount(ByVal proName As String) As Integer
Dim objWMIService As Object
Dim colProcessList As Object
Dim objProcess As Object
Dim objProType As Object
Dim strResult As String
Dim strTmp As String
Set objWMIService = GetObject("winmgmts:" & "{impersonationlevel=impersonate}!\\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name='" & proName & "'")
getInstanceCount = colProcessList.Count
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询