Results 1 to 2 of 2

Thread: provoked crash?

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    Mentor,Oh,US
    Posts
    33
    Does anyone know of a way to crash a program NOT VB!? I'm sure there's a way to do it.

    Anything?
    If at first you DO succeed, don't look too astonished!
    -deadBird
    =================

  2. #2
    Addicted Member Shrog's Avatar
    Join Date
    Aug 1999
    Location
    Darkest Africa
    Posts
    186

    Smile This works quite well

    Give this a try:

    Code:
    Option Explicit
    Option Compare Text
    
    Declare Function EnumWindows Lib "user32" _
                    (ByVal wndenmprc As Long, _
                     ByVal lParam As Long) As Long
    Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
                    (ByVal hwnd As Long, _
                     ByVal lpString As String, _
                     ByVal cch As Long) As Long
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
                    (ByVal hwnd As Long, _
                     ByVal wMsg As Long, _
                     ByVal wParam As Long, _
                     lParam As Any) As Long
    
    Public Const WM_CLOSE = &H10
    
    Private mTarget As String
    
    Public Sub TerminateTask(app_name As String)
      mTarget = app_name
      EnumWindows AddressOf EnumCallback, 0
    End Sub
    
    Public Function EnumCallback(ByVal app_hWnd As Long, ByVal param As Long) As Long
      Dim Buffer As String * 256
      Dim Title As String
      Dim Length As Long
    
      ' Get the window's title.
      Length = GetWindowText(app_hWnd, Buffer, Len(Buffer))
      Title = Left$(Buffer, Length)
      
      ' See if this is the target window.
      If InStr(Title, mTarget) <> 0 Then
        ' Kill the window.
        SendMessage app_hWnd, WM_CLOSE, 0, 0
      End If
      
      EnumCallback = 1
    
    End Function
    You can call the TerminateTask sub with a parameter like "Internet Explorer" or "Microsoft Word". The specified app will be killed.

    Hope this helps.
    Shrog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width