吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 5234|回复: 2
收起左侧

结束进程和重新启动的vbs脚本

 关闭 [复制链接]
阿冰 发表于 2008-9-30 12:11
按照提示存为t.vbs文件,在cmd窗口中输入cscript t.vbs [参数]就可以了。
如果想移植到vb下,把wscript.echo替换成debug.pring或者其他的输出函数就可以了

'function:
' list all process or kill one of them
'parameter:
NameorPID process's name or pid
'return:
' true if kill one process, else false
Function KillProcess(NameorPID)
Dim oWMI, oProcs, oProc, strSQL
KillProcess = False
strSQL = "SELECT * FROM Win32_Process"
If NameOrPID <> "" Then
If IsNumeric(NameOrPID) Then
strSQL = strSQL & " WHERE Handle = &#39;" & NameorPID & "&#39;"
Else
strSQL = strSQL & " WHERE Name = &#39;" & NameorPID & "&#39;"
End If
End If
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set oProcs = oWMI.ExecQuery(strSQL)
For Each oProc In oProcs
If IsNumeric(NameOrPID) Then
oProc.Terminate
WScript.Echo oProc.Name & "(" & oProc.Handle & ") was killed!"
KillProcess = True
Else
WScript.Echo "Name: " & oProc.Name & vbTab & "PID: " & oProc.Handle & _
vbCrLf & vbTab & "Path: " & oProc.ExecutablePath
End If
Next
Set oProc = Nothing
Set oProcs = Nothing
Set oWMI = Nothing
End Function

&#39;function:
&#39; reboot or shutdown operating system
&#39;parameter:
&#39; RorS "r"=reboot, "s" or others="shutdown"
&#39;return:
&#39; none
Function Reboot(RorS)
Dim oWMI, oSys, oOpSys
Set oWMI = GetObject("winmgmts:{(shutdown)}!\\.\root\cimv2")
Set oOpSys = oWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each oSys In oOpSys
If Instr(LCase(RebootOrShut),"r") > 0 Then
WScript.Echo "Reboot..."
oSys.Reboot
Else
WScript.Echo "Shuting down..."
oSys.Shutdown
End If
Next
Set oOpSys = Nothing
Set oSys = Nothing
Set oWMI = Nothing
End Function

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

627229263 发表于 2010-8-14 00:55
下下来看看
datochan 发表于 2010-8-15 18:10
为了防止灌水,我已将本主题执行下沉操作。
本楼之后的跟贴,当作水贴处理。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-17 02:46

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表