Have fun with Windows message boxes

Hello everyone, today we are going to focus on our computers and more particularly on those under Windows. We will generate a Windows message box using the following programming language: Visual Basic. Don’t worry, no prerequisites are necessary to fol…


This content originally appeared on DEV Community and was authored by Clément Gaudinière

Hello everyone, today we are going to focus on our computers and more particularly on those under Windows. We will generate a Windows message box using the following programming language: Visual Basic. Don't worry, no prerequisites are necessary to follow this tutorial and all the steps will be explained. Through this article we will also see how to enrich and improve our message box, so that, for example, it can no longer be closed, that it remains in the foreground, etc. This way you can joke with your friends in a friendly manner, as there are several solutions to remove a dialogue box that cannot be closed. This type of dialog box can also be called fake virus, since it can worry the person at first, even if it does not affect the user's computer in any way. You can already see what the dialog box will look like at the end:

Box message exemple

The basics

To begin with, you will need your computer running the Windows operating system. Once turned on, we will use the basic notepad software installed on almost all computers in the operating system. If you do not have a notepad, you can also use a code editor.

Notepad editor

Once open we will write our first line of code :

msgbox "Your text here"

Once written, click on "File", then on "Save as", now give your file a name in the following form: name.vbs. Then click on "Save". It is important to specify the extension of the .vbs file, otherwise the file will be executed as a text file and no action will be performed. VBS means Visual Basic Script. Once saved, the file icon will normally look like this:

File vbs

If you double click on this file you will see a windows dialogue box open, which you can close by clicking on "Ok" or on the cross.

A non-closable message box

Now we are going to add a few lines of code so that our box can no longer be closed simply with the cross, nor with "Ok". To do this, we will use the Visual Basic Do...Loop statement. The previously written code will be wrapped up in the do and loop instructions :

do
msgbox "Your text here"
loop

We re-save the file as a .vbs file, and when we execute the file, we will not be able to close it simply with the cross or with the "Ok" button, since the loop instruction allows to create an infinite loop.

You can also put several messages in your code :

do
msgbox "Your text here"
msgbox "Your other text here"
loop

So once both messages have been read, the code will go back to the beginning and read the first and second messages over and over again. To permanently close a message box, go to the Windows Task Manager. For example, you can right-click in the navigation bar and then click on Task Manager. Once this is done, click on "Microsoft Windows Based Script Host" and then on "End Task". If you can't find it, here's an overview of what to find :

Task

You can also turn off your computer, and all messages will be gone the next time you turn it on.

Customise the message box

Before you become a Windows message box pro, you need to know the different ways to customise it. Indeed you can for example give a title to your message box, add a critical error icon, a questioning warning... We will also see how to make sure that our dialog box is always in the foreground. In the following non-functional piece of code, the variables x, y, z can have several values :

' Non-functional code
do
msgbox "Your text here",x+y+z,"Title"
loop

We will detail these values later, but first let's break down the msgbox. The first string in quotes represents the text inside the dialog box, the x allows you to define the buttons of the dialog box, the y enables you to put an icon, and the z permits you to make the message box always in the foreground. Finally, the last string represents the title of the popup.

Let's first look at the x, this is a number which can have different values and which allows the buttons to be defined. All the values of x and their effects are here, in the table below :

x Effect
0 OK button
1 OK and Cancel buttons
2 Abort, Restart and Ignore buttons
3 Yes, No and Cancel buttons
4 Yes and No buttons
5 Restart and Cancel buttons

Then the values of y can be as follows :

y Effect
16 Critical error icon
32 Interrogative warning icon
48 Simple warning icon
64 Message icon

Finally, the z values can be :

z Effect
0 Normal dialogue box
4096 Dialog box always in the foreground

Let's put into practice what we have just learned, if we want to create a message box that is always in the foreground, with the title "Virus", the content "Trojan Horse", with the Ok and Cancel buttons and with a critical error icon, our code will look like this :

do
msgbox "Trojan Horse",1+16+4096,"Virus"
loop

To go further

To go further and make a joke to your friends, we will see how to customize the appearance of our vbs file, so that it looks like a web browser. For example the following icon refers to a vbs file which opens an infinite message box :

Shortcut

To do this, you need to save your vbs file anywhere unobtrusively. Then right click and click on "copy". Then go to the place where you want to create your shortcut and right click and "paste shortcut". Then right click on the item you have just created and click on "Properties" and then "Change Icon" in the "Shortcut" tab. Choose the icon you prefer then click on "Ok" then on "Apply". All that's left to do is rename it and you're done!

I hope you enjoyed this tutorial, if you liked the concept, I might do another article on fake viruses. If you have any questions, feel free to ask me in the comments. 👍


This content originally appeared on DEV Community and was authored by Clément Gaudinière


Print Share Comment Cite Upload Translate Updates
APA

Clément Gaudinière | Sciencx (2021-10-02T16:40:17+00:00) Have fun with Windows message boxes. Retrieved from https://www.scien.cx/2021/10/02/have-fun-with-windows-message-boxes/

MLA
" » Have fun with Windows message boxes." Clément Gaudinière | Sciencx - Saturday October 2, 2021, https://www.scien.cx/2021/10/02/have-fun-with-windows-message-boxes/
HARVARD
Clément Gaudinière | Sciencx Saturday October 2, 2021 » Have fun with Windows message boxes., viewed ,<https://www.scien.cx/2021/10/02/have-fun-with-windows-message-boxes/>
VANCOUVER
Clément Gaudinière | Sciencx - » Have fun with Windows message boxes. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/02/have-fun-with-windows-message-boxes/
CHICAGO
" » Have fun with Windows message boxes." Clément Gaudinière | Sciencx - Accessed . https://www.scien.cx/2021/10/02/have-fun-with-windows-message-boxes/
IEEE
" » Have fun with Windows message boxes." Clément Gaudinière | Sciencx [Online]. Available: https://www.scien.cx/2021/10/02/have-fun-with-windows-message-boxes/. [Accessed: ]
rf:citation
» Have fun with Windows message boxes | Clément Gaudinière | Sciencx | https://www.scien.cx/2021/10/02/have-fun-with-windows-message-boxes/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.