Friday, January 9, 2015

Code to kill all the other wscripts running on the system Except current wscript || Vb Script || shell

    'Create windows management object
    Dim objWinMgmts
    Dim process_List
    Set objWinMgmts = GetObject("WinMgmts:Root\Cimv2")
    'Get the list of all the wscripts running in the system
    Set process_List = objWinMgmts.ExecQuery("Select * From Win32_Process where name='wscript.exe'")
    'Get the process id of the current executing wscript ('this' object)
    Dim cpid, cpst
    cpid = 0
    cpst = FormatDateTime("01/01/1900")
    For Each objProcess In process_List
        If objProcess.CreationDate > cpst Then
            cpid = objProcess.ProcessId
            cpst = objProcess.CreationDate
        End If
    Next
    'Except current wscript, kill all the other wscripts running on the system
    For Each objProcess In colProcess
        If cpid <> objProcess.ProcessId Then
            objProcess.Terminate
        End If
    Next
    Set process_List = Nothing
    Set objWinMgmts = Nothing

No comments:

Post a Comment