按照提示存为t.vbs文件,在cmd窗口中输入cscriptt.vbs[参数]就可以了。
如果想移植到vb下,把wscript.echo替换成debug.pring或者其他的输出函数就可以了
'function:
'listallprocessorkilloneofthem
'parameter:
NameorPIDprocess'snameorpid
'return:
'trueifkilloneprocess,elsefalse
FunctionKillProcess(NameorPID)
DimoWMI,oProcs,oProc,strSQL
KillProcess=False
strSQL="SELECT*FROMWin32_Process"
IfNameOrPID<>""Then
IfIsNumeric(NameOrPID)Then
strSQL=strSQL&"WHEREHandle='"&NameorPID&"'"
Else
strSQL=strSQL&"WHEREName='"&NameorPID&"'"
EndIf
EndIf
SetoWMI=GetObject("winmgmts:\\.\root\cimv2")
SetoProcs=oWMI.ExecQuery(strSQL)
ForEachoProcInoProcs
IfIsNumeric(NameOrPID)Then
oProc.Terminate
WScript.EchooProc.Name&"("&oProc.Handle&")waskilled!"
KillProcess=True
Else
WScript.Echo"Name:"&oProc.Name&vbTab&"PID:"&oProc.Handle&_
vbCrLf&vbTab&"Path:"&oProc.ExecutablePath
EndIf
Next
SetoProc=Nothing
SetoProcs=Nothing
SetoWMI=Nothing
EndFunction
'function:
'rebootorshutdownoperatingsystem
'parameter:
'RorS"r"=reboot,"s"orothers="shutdown"
'return:
'none
FunctionReboot(RorS)
DimoWMI,oSys,oOpSys
SetoWMI=GetObject("winmgmts:{(shutdown)}!\\.\root\cimv2")
SetoOpSys=oWMI.ExecQuery("SELECT*FROMWin32_OperatingSystem")
ForEachoSysInoOpSys
IfInstr(LCase(RebootOrShut),"r")>0Then
WScript.Echo"Reboot..."
oSys.Reboot
Else
WScript.Echo"Shutingdown..."
oSys.Shutdown
EndIf
Next
SetoOpSys=Nothing
SetoSys=Nothing
SetoWMI=Nothing
EndFunction
如果想移植到vb下,把wscript.echo替换成debug.pring或者其他的输出函数就可以了
'function:
'listallprocessorkilloneofthem
'parameter:
NameorPIDprocess'snameorpid
'return:
'trueifkilloneprocess,elsefalse
FunctionKillProcess(NameorPID)
DimoWMI,oProcs,oProc,strSQL
KillProcess=False
strSQL="SELECT*FROMWin32_Process"
IfNameOrPID<>""Then
IfIsNumeric(NameOrPID)Then
strSQL=strSQL&"WHEREHandle='"&NameorPID&"'"
Else
strSQL=strSQL&"WHEREName='"&NameorPID&"'"
EndIf
EndIf
SetoWMI=GetObject("winmgmts:\\.\root\cimv2")
SetoProcs=oWMI.ExecQuery(strSQL)
ForEachoProcInoProcs
IfIsNumeric(NameOrPID)Then
oProc.Terminate
WScript.EchooProc.Name&"("&oProc.Handle&")waskilled!"
KillProcess=True
Else
WScript.Echo"Name:"&oProc.Name&vbTab&"PID:"&oProc.Handle&_
vbCrLf&vbTab&"Path:"&oProc.ExecutablePath
EndIf
Next
SetoProc=Nothing
SetoProcs=Nothing
SetoWMI=Nothing
EndFunction
'function:
'rebootorshutdownoperatingsystem
'parameter:
'RorS"r"=reboot,"s"orothers="shutdown"
'return:
'none
FunctionReboot(RorS)
DimoWMI,oSys,oOpSys
SetoWMI=GetObject("winmgmts:{(shutdown)}!\\.\root\cimv2")
SetoOpSys=oWMI.ExecQuery("SELECT*FROMWin32_OperatingSystem")
ForEachoSysInoOpSys
IfInstr(LCase(RebootOrShut),"r")>0Then
WScript.Echo"Reboot..."
oSys.Reboot
Else
WScript.Echo"Shutingdown..."
oSys.Shutdown
EndIf
Next
SetoOpSys=Nothing
SetoSys=Nothing
SetoWMI=Nothing
EndFunction
博客介绍了将脚本存为t.vbs文件并在cmd窗口运行的方法,还提及移植到vb下的输出函数替换。同时给出了KillProcess函数用于列出或终止进程,以及Reboot函数用于重启或关机操作,包含函数的参数和返回值说明。
9398

被折叠的 条评论
为什么被折叠?



