飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 2528|回复: 0

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

[复制链接]
  • TA的每日心情
    难过
    5 天前
  • 签到天数: 11 天

    [LV.3]偶尔看看II

    发表于 2005-3-4 09:57:55 | 显示全部楼层 |阅读模式
    按照提示存为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 = '" & NameorPID & "'"
            Else
                strSQL = strSQL & " WHERE Name = '" & NameorPID & "'"
            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

    'function:
    ' reboot or shutdown operating system
    'parameter:
    ' RorS "r"=reboot, "s" or others="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(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
    PYG19周年生日快乐!
    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

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