VB获取打开的程序个数代码

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

发布日期:

所属分类: 编程 标签:


没有相关文章!