vbs+hta 实现同时关闭多个系统进程
2007-09-04 09:50
267 查看
本代码通过 xp mshta.exe 解析执行
-----------------------------------------------------------------------------------
<HEAD>
<title>进程中断</title>
<HTA:APPLICATION
APPLICATIONNAME="进程中断"
BORDER="THICK"
caption="进程中断"
maximizebotton="yes"
minmizebutton="yes"
scroll="yes"
showintaskbar="yes"
singleinstance="yes"
sysmenu="yes"
windowstate="maximize"
>
</HEAD>
<SCRIPT LANGUAGE="VBScript">
Set os0=createobject("shell.application")
Set wmi=GetObject("winmgmts://.")
Set d0=CreateObject("scripting.dictionary")
Sub list
d0.RemoveAll
n=1
dataarea.innerhtml=Nothing
strHTML = strhtml&"<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
strhtml = strhtml&"<tr>"& _
"<td width='3%'>"&"<font size=2>"&"序号"&"</font>"&"</td>"& _
"<td width='20%'>"&"<font size=2>"&"名称"&"</font>"&"</td>"& _
"<td width='7%'>"&"<font size=2>"&"PID"&"</font>"&"</td>"& _
"<td width='70%'>"&"<font size=2>"&"命令行"&"</font>"&"</td>"
Set pro_s=wmi.instancesof("win32_process")
For Each p In pro_s
strhtml = strhtml&"<tr>"& "<td width='3%'>"& _
"<font size=2>"&n&"</font>"&"</td>"&"<td width='20%'>"& _
"<font size=2>"&p.name&"</font>"&"</td>"& "<td width='7%'>"& _
"<font size=2>"&p.handle&"</font>"&"</td>"& "<td width='70%'>"& _
"<font size=2>"&p.commandline&"</font>" _
&"</td>"
d0.Add ""&n,Trim(p.handle)
n=n+1
Next
dataarea.innerhtml=strhtml
End Sub
Sub stop_p
xs=Split(txt.value,",",-1,1)
for i=0 to ubound(xs)
for n=0 to ubound(xs)
if n=i then
n=n+1
if n>ubound(xs) then exit for
end if
if xs(n)=xs(i) or _
Trim(xs(n))="" Then
xs(n)="-1"
end If
next
Next
w=0
For i=0 To UBound(xs)
If d0.Exists(xs(i))=False Then
xs(i)="-2"
w=w+1
End If
Next
w=(UBound(xs)+1-w)
If w=0 Then
MsgBox "需要中断的进程序号列表无效,"&Chr(13)& _
"可能需要关闭的进程不存在或者输入的序号格式不正确,请打开进程列表确认!"
Else
strhtml="<font size=2>"&"已被中断的进程"&"</font>"&"<br>"
strHTML = strhtml&"<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
For i=0 To UBound(xs)
If xs(i) <> "-2" Then
Set pro_s=wmi.EXECQUERY("Select * FROM WIN32_PROCESS Where HANDLE='"&D0(XS(I))&"'" )
N=1
For Each p In pro_s
pd=p.terminate()
If pd=0 Then
strhtml = strhtml&"<tr>"& "<td width='3%'>"&"<font size=2>"&xs(i)&"</font>"&"</td>"& _
"<td width='20%'>"&"<font size=2>"&p.name&"</font>"&"</td>"& _
"<td width='7%'>"&"<font size=2>"&p.handle&"</font>"&"</td>"& _
"<td width='70%'>"&"<font size=2>"&p.commandline&"</font>"&"</td>"
D0.Remove(xs(i))
n=n+1
End If
Next
If N=0 Then '要关闭的进程可能被牵连关闭了
strhtml = strhtml&"<tr>"& "<td width='3%'>"& _
"<font size=2>"&xs(i)&"</font>"&"</td>"&"<td width='20%'>"& _
"<font size=2>"&p.name&"</font>"&"</td>"& "<td width='7%'>"& _
"<font size=2>"&p.handle&"</font>"&"</td>"& "<td width='70%'>"& _
"<font size=2>"&p.commandline&" 已经被间接关闭"&"</font>"& _
"</td>"
D0.Remove(xs(i))
End if
End If
Next
dataarea.innerhtml=dataarea.innerhtml&strhtml
txt.value=""
End If
End Sub
</SCRIPT>
<body>
<input type="button" value="进程列表" name="list_button" onClick="list"><p>
<span id="dataarea"></span><br>
输入欲中断的进程序号,如:1,2,5,7,55...
<input type="text" name="txt" size=60 value="">
<input type="button" value="中断进程" name="stop_p_button" onClick="stop_p">
<p>
</body>
-----------------------------------------------------------------------------------
<HEAD>
<title>进程中断</title>
<HTA:APPLICATION
APPLICATIONNAME="进程中断"
BORDER="THICK"
caption="进程中断"
maximizebotton="yes"
minmizebutton="yes"
scroll="yes"
showintaskbar="yes"
singleinstance="yes"
sysmenu="yes"
windowstate="maximize"
>
</HEAD>
<SCRIPT LANGUAGE="VBScript">
Set os0=createobject("shell.application")
Set wmi=GetObject("winmgmts://.")
Set d0=CreateObject("scripting.dictionary")
Sub list
d0.RemoveAll
n=1
dataarea.innerhtml=Nothing
strHTML = strhtml&"<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
strhtml = strhtml&"<tr>"& _
"<td width='3%'>"&"<font size=2>"&"序号"&"</font>"&"</td>"& _
"<td width='20%'>"&"<font size=2>"&"名称"&"</font>"&"</td>"& _
"<td width='7%'>"&"<font size=2>"&"PID"&"</font>"&"</td>"& _
"<td width='70%'>"&"<font size=2>"&"命令行"&"</font>"&"</td>"
Set pro_s=wmi.instancesof("win32_process")
For Each p In pro_s
strhtml = strhtml&"<tr>"& "<td width='3%'>"& _
"<font size=2>"&n&"</font>"&"</td>"&"<td width='20%'>"& _
"<font size=2>"&p.name&"</font>"&"</td>"& "<td width='7%'>"& _
"<font size=2>"&p.handle&"</font>"&"</td>"& "<td width='70%'>"& _
"<font size=2>"&p.commandline&"</font>" _
&"</td>"
d0.Add ""&n,Trim(p.handle)
n=n+1
Next
dataarea.innerhtml=strhtml
End Sub
Sub stop_p
xs=Split(txt.value,",",-1,1)
for i=0 to ubound(xs)
for n=0 to ubound(xs)
if n=i then
n=n+1
if n>ubound(xs) then exit for
end if
if xs(n)=xs(i) or _
Trim(xs(n))="" Then
xs(n)="-1"
end If
next
Next
w=0
For i=0 To UBound(xs)
If d0.Exists(xs(i))=False Then
xs(i)="-2"
w=w+1
End If
Next
w=(UBound(xs)+1-w)
If w=0 Then
MsgBox "需要中断的进程序号列表无效,"&Chr(13)& _
"可能需要关闭的进程不存在或者输入的序号格式不正确,请打开进程列表确认!"
Else
strhtml="<font size=2>"&"已被中断的进程"&"</font>"&"<br>"
strHTML = strhtml&"<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
For i=0 To UBound(xs)
If xs(i) <> "-2" Then
Set pro_s=wmi.EXECQUERY("Select * FROM WIN32_PROCESS Where HANDLE='"&D0(XS(I))&"'" )
N=1
For Each p In pro_s
pd=p.terminate()
If pd=0 Then
strhtml = strhtml&"<tr>"& "<td width='3%'>"&"<font size=2>"&xs(i)&"</font>"&"</td>"& _
"<td width='20%'>"&"<font size=2>"&p.name&"</font>"&"</td>"& _
"<td width='7%'>"&"<font size=2>"&p.handle&"</font>"&"</td>"& _
"<td width='70%'>"&"<font size=2>"&p.commandline&"</font>"&"</td>"
D0.Remove(xs(i))
n=n+1
End If
Next
If N=0 Then '要关闭的进程可能被牵连关闭了
strhtml = strhtml&"<tr>"& "<td width='3%'>"& _
"<font size=2>"&xs(i)&"</font>"&"</td>"&"<td width='20%'>"& _
"<font size=2>"&p.name&"</font>"&"</td>"& "<td width='7%'>"& _
"<font size=2>"&p.handle&"</font>"&"</td>"& "<td width='70%'>"& _
"<font size=2>"&p.commandline&" 已经被间接关闭"&"</font>"& _
"</td>"
D0.Remove(xs(i))
End if
End If
Next
dataarea.innerhtml=dataarea.innerhtml&strhtml
txt.value=""
End If
End Sub
</SCRIPT>
<body>
<input type="button" value="进程列表" name="list_button" onClick="list"><p>
<span id="dataarea"></span><br>
输入欲中断的进程序号,如:1,2,5,7,55...
<input type="text" name="txt" size=60 value="">
<input type="button" value="中断进程" name="stop_p_button" onClick="stop_p">
<p>
</body>
相关文章推荐
- vbs 实现瞬间关闭多个系统进程
- vbs 实现瞬间关闭多个系统进程
- 用vbs实现的瞬间关闭多个系统进程的脚本
- Windows系统使用vbs脚本或bat脚本强制杀死指定所有进程 vbs实现循环持续写入内容到vbs打开开的记事本 使用vbs、bat添加windows计划任务 使用cmd schtasks命令添加windows计划任务
- java实现关闭windos系统下的进程
- 巧妙的实现多个进程同时跑的问题~买票系统
- 实现后台检控并关闭进程的批处理
- PHP实现系统编程(五)--- 编写守护进程详解
- java代码实现开启openoffice服务和关闭sffice.exe进程
- P2P后台终结者源码.分享QT+WIN SDK实现.自动扫描后台关闭P2P后台进程
- [Windows 监控]使用windows自带的工具去对某一进程实现监控,并取得这一进程对系统的资源使用情况
- VC下通过系统快照实现进程管理的方法
- javascript实现点击按钮弹出一个可关闭层窗口同时网页背景变灰的方法
- Delphi获取系统进程和进程ID,Listview实现
- 获取系统进程快照 c语言实现
- windows系统调用 利用事件对象实现进程通信
- C#实现阻止关闭显示器和系统待机
- javascript实现点击按钮弹出一个可关闭层窗口同时网页背景变灰的方法
- 发现系统中有Excel进程,要关闭所有Excel进程
- MFC中实现关闭软件系统