早教吧作业答案频道 -->其他-->
VB关闭某项进程的Dimprocname$,rtn&PrivateSubCommand1Click()procname="explorer.exe"strcomputer="."SetobjWMIService=GetObject("winmgmts:"&"{impersonationLevel=impersonate}!\\.\root\cimv2")SetcolProcessList=objWMIService.Exec
题目详情
VB关闭某项进程的Dim procname$, rtn& Private Sub Command1_Click() procname = "explorer.exe" strcomputer = "." Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & procname & "'") If colProcessList.Count = 0 Then MsgBox procname & " 没有运行" Else For Each objProcess In colProcessList rtn = MsgBox("您确定要终止 " & procname & " 吗?", vbYesNo, "强制关闭进程") If rtn = 6 Then objProcess.Terminate Next End If 这个帮我解释一下每句的代码...谢谢
▼优质解答
答案和解析
这是wmi 脚本 ======== WMI是英文Windows Management Instrumentation的简写,它的功能主要是:访问本地主机的一些信息和服务,可以管理远程计算机(当然你必须要拥有足够的权限),比如:重启,关机,关闭进程,创建进程等。 =================== Dim procname$, rtn& Private Sub Command1_Click() procname = "explorer.exe"'进程名称为explorer.exe strcomputer = "."'查找本地计算机 Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")'取得系统信息 Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & procname & "'")'找出所有名称为explorer.exe的进程 If colProcessList.Count = 0 Then'如果没有名称为explorer.exe的进程就提示 MsgBox procname & " 没有运行" Else For Each objProcess In colProcessList'循环关闭所有名称为explorer.exe的进程 rtn = MsgBox("您确定要终止 " & procname & " 吗?", vbYesNo, "强制关闭进程") If rtn = 6 Then objProcess.Terminate'如果选择了YES 关闭进程 Next End If
看了VB关闭某项进程的Dimpro...的网友还看了以下: