Solved

Kill all Messagebox in Visual studio 2008

Posted on 2009-07-11
7
558 Views
Last Modified: 2013-11-27
I want to kill all messagebox from external program , or kill all open messagebox  in windows. thanks a lot
0
Comment
Question by:Gknrsy
  • 6
7 Comments
 

Author Comment

by:Gknrsy
Comment Utility
i found some c# codes but i don't know how in vb2008

// showbox.cs

using System;
using System.Windows.Forms;

class Program
{
    static void Main()
    {
       Application.Run(new ShowBox());      
    }
}

class ShowBox : Form
{
    private Button btn;

    public ShowBox()
    {
       btn = new Button();
       btn.Text = "Press me";
       btn.Click += new EventHandler(button_Click);
       this.Controls.Add(btn);
    }

    private void button_Click(object sender, EventArgs e)
    {
       MessageBox.Show(this, "Hello from Show Box", "Greeting");
    }
}  

// capturebox.cs

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;

class CaptureBox
{
    [DllImport("user32.dll")]
    static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);


    static IntPtr hwndParent;

    static void Main()
    {
        Process[] procs = Process.GetProcessesByName("showbox");

        if (procs.Length == 0)
        {
            Console.WriteLine("Showbox isn't running");
            return;
        }
     
        hwndParent = procs[0].MainWindowHandle;

        bool hasAppeared = false;

        do        
        {
            if (!procs[0].HasExited)
            {
               hasAppeared = CheckMessageBox();
               Thread.Sleep(1000); // check every second
            }
            else
            {
               Console.WriteLine("Showbox has exited");
               break;
            }
        }          
        while(!hasAppeared);
    }

    static bool CheckMessageBox()
    {
        // IntPtr hwndMB = FindWindowEx(hwndParent, IntPtr.Zero, "#32770", "Greeting");
        // Apparently MessageBox is always top level in .NET
        IntPtr hwndMB = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "Greeting");
        if (hwndMB == IntPtr.Zero)
        {
           Console.WriteLine("MessageBox not showing");
           return false;
        }
        else
        {          
           Console.WriteLine("MessageBox has appeared");
           return true;
        }
    }
}
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 300 total points
Comment Utility
Below is a VB translation of the code you posted. For the class CaptureBox, I started a VB Console Application project and put the code inside a module file.
''''''''''''''''''''''''''''''''''''''''''''

'' Showbox code

''''''''''''''''''''''''''''''''''''''''''''

Public Class ShowBox

    Private btn As Button
 

    Public Sub New()

        ' This call is required by the Windows Form Designer.

        InitializeComponent()
 

        ' Add any initialization after the InitializeComponent() call.

        btn = New Button()

        btn.Text = "Press me"

        AddHandler btn.Click, AddressOf button_Click

        Controls.Add(btn)

    End Sub
 

    Private Sub button_Click(ByVal sender As Object, ByVal e As EventArgs)

        MessageBox.Show(Me, "Hello from Show Box", "Greeting")

    End Sub
 

End Class
 

''''''''''''''''''''''''''''''''''''''''''''

'' CaptureBox code

''''''''''''''''''''''''''''''''''''''''''''

Imports System.Runtime.InteropServices

Imports System.Diagnostics

Imports System.Threading
 

Module Module1

    Dim hwndParent As IntPtr
 

    Sub Main()

        Dim procs() As Process = Process.GetProcessesByName("showbox")
 

        If procs.Length = 0 Then

            Console.WriteLine("Showbox isn't running.");

            Return

        End If
 

        hwndParent = procs(0).MainWindowHandle
 

        Dim hasAppeared As Boolean = False
 

        Do

            If Not procs(0).HasExited Then

                hasAppeared = CheckMessageBox()

                Thread.Sleep(1000)

            Else

                Console.WriteLine("Showbox has exited")

                Exit Do

            End If

        Loop While Not hasAppeared

    End Sub
 

    Function CheckMessageBox() As Boolean

        Dim hwndMB As IntPtr = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "Greeting")
 

        If hwndMB = IntPtr.Zero Then

            Console.WriteLine("MessageBox not showing.")

            Return False

        Else

            Console.WriteLine("MessageBox has appeared")

            Return True

        End If

    End Function
 

    <DllImport("user32.dll")> _

    Function FindWindowEx(ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr

    End Function
 
 

End Module

Open in new window

0
 

Author Comment

by:Gknrsy
Comment Utility
i just found this code in internet. is it working??
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:Gknrsy
Comment Utility
i asked because just tomarrow i will try :)
0
 

Author Comment

by:Gknrsy
Comment Utility
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports System.Threading
Module Module1



    Dim hwndParent As IntPtr



    Function CheckMessageBox() As Boolean
        Dim hwndMB As IntPtr = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "Greeting!")

        If hwndMB = IntPtr.Zero Then
            MsgBox("MessageBox not showing.")
            Return False
        Else
            MsgBox("MessageBox has appeared")
            Return True
        End If
    End Function

    <DllImport("user32.dll")> _
    Function FindWindowEx(ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
    End Function


End Module

with this code i am checking messagebox working or not .

now if messagebox working how i will close this message box?


0
 

Author Comment

by:Gknrsy
Comment Utility

    Function CheckMessageBox() As Boolean
        Dim hwndMB As IntPtr = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "Hello")

        If hwndMB = IntPtr.Zero Then
            Exit Function
            Return False
        Else
            Dim procs() As Process = Process.GetProcessesByName("ABC")
            AppActivate(procs(0).Id)
            SendKeys.Send("{enter}") ' this sends F5 to the window
            Return True
        End If
    End Function

i wite this code , but this code working with focus i mean when sending enter key to messagebox it becomes active. i want to send enter key or just kill message box background , i don't want to it brings front :) sorry for bad explanation.
0
 

Accepted Solution

by:
Gknrsy earned 0 total points
Comment Utility
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports System.Threading
Module Module1

    Dim hwndParent As IntPtr

    Function CheckMessageBox() As Boolean
        Dim hwndMB As IntPtr = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "")

        If hwndMB = IntPtr.Zero Then
            Exit Function
            Return False
        Else
           SendMessage(hwndMB, WM_CLOSE, 0, 0)
            Return True
        End If
    End Function

    <DllImport("user32.dll")> _
   Function SendMessage(ByVal hwnd As IntPtr, ByVal wMsg As IntPtr, ByVal wParam As Long, _
    ByVal lParam As Long) As Long

    End Function

    Private Const WM_CLOSE = &H10


    <DllImport("user32.dll")> _
    Function FindWindowEx(ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
    End Function


End Module


This is working very well :)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now