Visual Kill -9

Here is some Visual Basic script code which allows you to terminate a process given a process id number.

' Kills a program given its process id.
Function ProgKill(strProcessId)
   ' Declare used variables
   Dim strWQL
   Dim objProcess
   Dim objResult
   Dim intReturnCode
   Dim wmi

   Set wmi = GetObject("winmgmts:")
   ' Get Process by WMI
   strWQL = _
      "select * from win32_process where ProcessId='" _
      & strProcessId & "'"
   Set objResult = wmi.ExecQuery(strWQL)

   ' Kill all found process
   For Each objProcess in objResult
      ' Try to kill the process
      intReturnCode = objProcess.Terminate(0)
   Next
End Function

You can use code like this to kill a process started in your script after a given event or set time.

Related posts:

  1. Visual Basic And The Java Platform
  2. Print HTML Using IE
  3. Default Printer
  4. How To Kill A Community
  5. Windows Hack

This entry was posted in DotNET, TechKnow, Visual Basic. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*