• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1763
  • Last Modified:

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

please advise
0
itbabe
Asked:
itbabe
2 Solutions
 
merowingerCommented:
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

0
 
Daz_1234Commented:
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"
Else
   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"
Else
   MsgBox "You clicked No"
End If

Open in new window


If you look here:

http://msdn.microsoft.com/en-us/library/sfw6660x(v=vs.85).aspx

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

Hope this helps,
Daz.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now