Thursday, February 3, 2011

Kill all Processes on desktop

' Killing Excel process methods

1.

Systemutil.CloseProcessByName “Excel.exe”
'(Excel.exe is the process name which we need to close processes)

2.

strComputer = "."
strProcessKill = "'Excel.exe'"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
    objProcess.Terminate()
Next


or

Function KillProcess(ProcessName)
    Dim ObjInstances,ObjService, IntStatusCode, IntTerminationCode
    Set ObjService = GetObject("Winmgmts:")
    For Each Process in ObjService.InstancesOf("Win32_Process")
        If Ucase(Process.Name) = ProcessName Then
             StrPropath = "Win32_Process.Handle="& Process.ProcessId
             Set ObjInstances= ObjService.Get(StrProPath)
             IntStatus = ObjInstances.Terminate(IntTerminationCode)
             If IntStatus = 0 Then
                 Msgbox "Excel Service has been terminated"
             End If
         End If
    Next
Set ObjService = Nothing
Set ObjInstances = Nothing
End Function

' Calling function with an argument which process need to kill
KillProcess ("EXCEL.EXE")



Function KillingProcess(ProcessName)
    StrComp = "."
    Set ObjService = GetObject("Winmgmts://"&StrComp&"/root/Cimv2")
    Set TotalProcesses= ObjService.ExecQuery("Select * from Win32_Process")
    For Each ProName in TotalProcesses
        If Ucase(ProName.Name) = ProcessName Then
            ProName.Terminate
        End If
    Next

    Set TotalProceses = Nothing
    Set ObjService = Nothing
 End Function

' Calling function with an argument which process need to kill
KillingProcess("EXCEL.EXE")




"A good threat is worth a thousand tests" - Boris Beizer

No comments:

There was an error in this gadget