1. Home
  2. Windows Tips
  3. Show message box windows 10

How to show a message box on Windows 10

Apps can show alerts when they need a user’s attention e.g., the ‘Do you want to save changes’ alert you try to close a Notepad file with unsaved changes. They can also show messages e.g. when a file has downloaded or it has been processed.

These messages are useful but they don’t have to come from an app. Users can show a custom message box on Windows 10 using a batch script, PowerShell script, or by running a command in Command Prompt or PowerShell. 

Need to show a toast notification? Use a PowerShell module.

Custom message box on Windows 10

A custom message box will have a title, a message, and a call to action button i.e., an OK button which will dismiss the message. 

First, decide if you want to use a script or if you want to run a command. Running a command is easier so we’ll go over the script method first.

1. Batch/PowerShell script to show message box

Follow the steps below to create the script.

  1. Open a new Notepad file (or use any text editor of your choice).
  2. Paste the following in the Notepad file.
@echo off

powershell -Command "& {Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show('My Message', 'Message title', 'OK', [System.Windows.Forms.MessageBoxIcon]::Information);}"
  1. If you intend to use a PowerShell script, remove the first line: @echo off.
  2. Edit the script as below:
    • Replace ‘My Message‘ with the message you want the message box to show.
    • Replace “Message Title” with the title of the message box you want.

Example:

@echo off

powershell -Command "& {Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show('Go to the reactor room', 'Reactor Meltdown', 'OK', [System.Windows.Forms.MessageBoxIcon]::Information);}"
  1. Save the file with the .bat extension for a batch script or the .ps1 extension for a PowerShell script.
  2. Run the script and the message box will appear.

2. Command Prompt or PowerShell – Message box

Showing a message box from the Command Prompt or from PowerShell is easy. You do not need admin rights to show the message box.

Command Prompt

  1. Open Command Prompt.
  2. Run the following command in it.
  3. Edit the command as below to set your custom message and title.
    • Replace ‘My Message’ with the message you want the message box to show.
    • Replace “Message Title” with the title you want the message box to have.
@echo off

powershell -Command "& {Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show('My Message', 'Message Title', 'OK', [System.Windows.Forms.MessageBoxIcon]::Information);}"

PowerShell

  1. Open PowerShell.
  2. Run the following command.
  3. Edit the command to add your own message and title.
    • Replace ‘My Message’ with the message you want the message box to show.
    • Replace “Message Title” with the title you want the message box to have.
powershell -Command "& {Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show('My Message', 'Message Title', 'OK', [System.Windows.Forms.MessageBoxIcon]::Information);}"

1 Comment

  1. Exception calling “Show” with “4” argument(s): “Showing a modal dialog box or form when the application is
    not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or
    DefaultDesktopOnly style to display a notification from a service application.”
    At line:1 char:49
    + … dows.Forms; [System.Windows.Forms.MessageBox]::Show(‘thx for download …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + FullyQualifiedErrorId : InvalidOperationException

    trying to execute the script from a remote machine via SSH.
    ideas?