using
PowerShell
commands (into .NET assemblies)
@echo off
setlocal EnableDelayedExpansion
:: [REQUIRED for new lines in dialog text]
:: This sets up a delayed expansion !\n! variable for literal newlines, when needed.
(set \n=^
%=DO NOT REMOVE THIS LINE - This creates a variable for using newlines in PowerShell commands=%
)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Simple "OK" popup dialog
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set MSGBOX_TEXT=^Line One
set MSGBOX_TEXT=^!MSGBOX_TEXT!!\n!Line Two
powershell -c "Add-Type -Assembly System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show(\"${env:MSGBOX_TEXT}\")"
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Simple "OK" popup dialog with a title
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set MSGBOX_TITLE=^Hello Dialog!
set MSGBOX_TEXT=^Line One
set MSGBOX_TEXT=^!MSGBOX_TEXT!!\n!Line Two
powershell -c "Add-Type -Assembly System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show(\"${env:MSGBOX_TEXT}\", \"${env:MSGBOX_TITLE}\")"
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: "Yes"/"No" choice popup dialog
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Available types: OK, OKCancel, YesNo, YesNoCancel, RetryCancel, CancelTryContinue, AbortRetryIgnore
set MSGBOX_TYPE=YesNo
set MSGBOX_TITLE=^Hello Dialog!
set MSGBOX_TEXT=^Line One
set MSGBOX_TEXT=^!MSGBOX_TEXT!!\n!Line Two
for /f "usebackq delims=" %%i in (`
powershell -c "Add-Type -Assembly System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show(\"${env:MSGBOX_TEXT}\", \"${env:MSGBOX_TITLE}\", \"${env:MSGBOX_TYPE}\")"
`) do set MSGBOX_RESULT=%%i
echo ^Result: %MSGBOX_RESULT%
:: If your code is inside of an if() or for(), use !MSGBOX_RESULT! instead (delayed expansion)
echo ^Result: !MSGBOX_RESULT!
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Text input popup dialog
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set MSGBOX_TITLE=^Hello Dialog!
set MSGBOX_TEXT=^Line One
set MSGBOX_TEXT=^!MSGBOX_TEXT!!\n!Line Two
set MSGBOX_VALUE=^Default value
for /f "usebackq delims=" %%i in (`
powershell -c "Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::InputBox(\"${env:MSGBOX_TEXT}\", \"${env:MSGBOX_TITLE}\", \"${env:MSGBOX_VALUE}\")"
`) do set MSGBOX_RESULT=%%i
:: If the user selects "Cancel", the result will be an "" empty string
echo ^User Input: %MSGBOX_RESULT%
:: If your code is inside of an if() or for(), use !MSGBOX_RESULT! instead (delayed expansion)
echo ^User Input: !MSGBOX_RESULT!