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

按照提示存为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)