2个回答
展开全部
'添加一个模块将以下代码丢进去,并保存模块
Public Enum Progress
遍历进程 = 0
计算进程数 = 1
结束进程 = 2
End Enum
Public Function NL(Optional x As Long = 1)
For i = 1 To x
NL = NL & vbCrLf
Next
End Function
Public Function Tsk(Optional x, Optional y As Progress = 0)
On Error Resume Next
Select Case y
Case 遍历进程
Set j = GetObject("winmgmts:\\.\root\cimv2").execquery("select * from win32_process")
If x = "" Then
For Each i In j
Tsk = Tsk & i.Caption & NL
Next
Else
For Each i In j
If LCase(i.Caption) = LCase(x) Then Tsk = i.Caption
Next
End If
Case 计算进程数
Set j = GetObject("winmgmts:\\.\root\cimv2").execquery("select * from win32_process")
If x = "" Then
For Each i In j
z = z + 1
Next
Tsk = z
Else
For Each i In j
If LCase(i.Caption) = LCase(x) Then z = z + 1
Next
Tsk = z
End If
Case 结束进程
Set j = GetObject("winmgmts:\\.\root\cimv2").execquery("select * from win32_process where name='" & x & "'")
For Each i In j
i.Terminate
Next
End Select
End Function
'以下代码丢进窗体里
Private Sub Form_Load()
Text1.Text = ""
Text1.Text = Tsk
End Sub
Public Enum Progress
遍历进程 = 0
计算进程数 = 1
结束进程 = 2
End Enum
Public Function NL(Optional x As Long = 1)
For i = 1 To x
NL = NL & vbCrLf
Next
End Function
Public Function Tsk(Optional x, Optional y As Progress = 0)
On Error Resume Next
Select Case y
Case 遍历进程
Set j = GetObject("winmgmts:\\.\root\cimv2").execquery("select * from win32_process")
If x = "" Then
For Each i In j
Tsk = Tsk & i.Caption & NL
Next
Else
For Each i In j
If LCase(i.Caption) = LCase(x) Then Tsk = i.Caption
Next
End If
Case 计算进程数
Set j = GetObject("winmgmts:\\.\root\cimv2").execquery("select * from win32_process")
If x = "" Then
For Each i In j
z = z + 1
Next
Tsk = z
Else
For Each i In j
If LCase(i.Caption) = LCase(x) Then z = z + 1
Next
Tsk = z
End If
Case 结束进程
Set j = GetObject("winmgmts:\\.\root\cimv2").execquery("select * from win32_process where name='" & x & "'")
For Each i In j
i.Terminate
Next
End Select
End Function
'以下代码丢进窗体里
Private Sub Form_Load()
Text1.Text = ""
Text1.Text = Tsk
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询