How can I start a messagebox in vbscript that gets the focus

Posted on 2011-05-04
Last Modified: 2012-05-11
please advise
Question by:itbabe
    LVL 31

    Assisted Solution

    This should do it

    set objShell = CreateObject("Wscript.Shell")
    msgbox "this is a text",, "this is the title"
    objShell.AppActivate("this is the title")

    Open in new window

    LVL 12

    Accepted Solution

    MsgBox has the facility built-in to be displayed 'System Modal', which means the message is on top of all other windows and will remain so until dismissed.  This is not quite the same as 'focus' since it is possible to interact with other applications on the desktop, i.e. another window can have focus, but the message box remains on-top.

    The following will display a message box that will be displayed over all other windows:
    MsgBox "Hello World.", vbSystemModal, "Message Title"

    Open in new window

    The 'vbSystemModal' part of the statement can be added to in order to add custom buttons.  The following code displays 'Yes' and 'No' options and stores the return in variable iBtn:
    iBtn = MsgBox ("Hello World.", vbSystemModal + vbYesNo, "Message Title")
    If iBtn = vbYes Then
       MsgBox "You clicked Yes"
       MsgBox "You clicked No"
    End If

    Open in new window

    And you can add an icon, here a yellow exclamation mark by adding vbExclamation:
    iBtn = MsgBox ("Hello World.", vbSystemModal + vbYesNo + vbExclamation, "Message Title")
    If iBtn = vbYes Then
       MsgBox "You clicked Yes"
       MsgBox "You clicked No"
    End If

    Open in new window

    If you look here:

    There are all the possible constants you can use in a MsgBox command.

    Hope this helps,

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (…
    This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    746 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

    18 Experts available now in Live!

    Get 1:1 Help Now