End the process and restarted VBS scripts

xiaoxiao2021-03-06  42

Follow the prompts to the T.VBS file, enter the CScript T.vbs [parameter] in the CMD window.

If you want to port to VB, replace WScript.echo into debug.pring or other output functions.

'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 <> "" "" "

IF isnumeric (nameorpid) THEN

Strsql = strsql & "where handle = '" & nameorpid & "'"

Else

strsql = strsql & "where name = '" & nameorpid & "'"

END IF

END IF

Set Owmi = getObject ("WinMgmts: //./root/cimv2")

Set oprocs = oomi.execQuery (strsql)

For Each OPROC in Oprocs

IF isnumeric (nameorpid) THEN

OProc.Terminate

Wscript.echo oproc.name & "(" & opc.handle & ") WAS Killed!"

KillProcess = TRUE

Else

Wscript.echo "name:" & opc.name & vbtab & "PID:" & opc.handle & _

VBCRLF & VBTAB & "PATH:" & opc.executablePath

END IF

NEXT

Set oproc = Nothing

Set oprocs = Nothing

Set Owmi = Nothing

END FUNCTION

'Function:

'Reboot or Shutdown Operating System

'Parameter:

'RORS "R" = Reboot, "S" or ivHes = "shutdown"

'Return:

'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 (REBOTORSHUT), "R")> 0 thenwscript.echo "reboot ..."

OSYS.REBOOT

Else

WScript.echo "Shuting Down ..."

OSYS.SHUTDOWN

END IF

NEXT

SetOuggs = Nothing

Set OSYS = Nothing

Set Owmi = Nothing

END FUNCTION

转载请注明原文地址:https://www.9cbs.com/read-55035.html

New Post(0)