ID: 141
Viewed: 3521
Added: Apr 28, 2002
Version:
Snippet uploaded by: snippet
Written By: unknown
Demo: Sorry, no demo
Thank you for your vote. Please wait...
It appears you already voted for this snippet
It appears your vote value was empty
Kills Rogue Programs
Highlight all by clicking in box
<!---Declaration--->
Option Explicit
'
' Another sample found on the net somewhere....
'
' -------------------------------------------------
' Used by OpenProcess function
' -------------------------------------------------
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
' -------------------------------------------------
' API's used to get window info
' -------------------------------------------------
Private Declare Function DestroyWindow _
Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function IsWindow _
Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function OpenProcess _
Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle _
Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function TerminateProcess _
Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal uExitCode As Long) As Long
Private Declare Function GetWindowThreadProcessId _
Lib "user32" _
(ByVal hwnd As Long, _
lpdwProcessId As Long) As Long
Highlight All
<!---Code--->
Public Sub KillWindow(ByVal xlngWndHwnd As Long)
Dim plngPID As Long
Dim plngRtn As Long
Dim plngOpenProcHwnd As Long
plngRtn = GetWindowThreadProcessId(xlngWndHwnd, plngPID)
If plngPID > 0 Then
plngOpenProcHwnd = OpenProcess(PROCESS_ALL_ACCESS, 0&, plngPID)
If plngOpenProcHwnd <> 0 Then
DoIt xlngWndHwnd, plngOpenProcHwnd
plngRtn = CloseHandle(plngOpenProcHwnd)
End If
End If
End Sub
Private Sub DoIt(xlngHwnd As Long, xlngProcessHwnd As Long)
Dim plngRtn As Long
Dim plngProcessHwnd As Long
Dim plngThreadHwnd As Long
Dim plngExitCode As Long
plngExitCode = 0&
If xlngHwnd <> 0 Then
If IsWindow(xlngHwnd) <> 0 Then
plngRtn = TerminateProcess _
(xlngProcessHwnd, _
plngExitCode)
If plngRtn = 0 Then
MsgBox "Failed To destroy window: Error #" & _
Err.LastDllError & ", " & _
Err.LastDllError
Else
MsgBox "Destroyed window!"
End If
End If
End If
End Sub;
No Comments to show
Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.
Adding your comment. Please wait...
Thanks for adding your comment!. After further review it will be added.
There was a problem adding your comment. Please try again.
Please complete all the fields in the form before sending.