Search code examples
batch-filecmdmsgbox

Do a cmd command in a msgbox


So, my goal is that I want to get a msgbox that tells me what power plan I'm on without using the command prompt.

I've tried making a batch file but that only does the command.

start cmd /k powercfg/getactivescheme

When I try doing it from the command prompt it just outputs the text of the command in the msg box not the actual output.

msg %username% powerconfg/getactivescheme

Thanks in advance


Solution

  • Try like this (Use for to get your command output in a variable):

    @echo off
    for /f "tokens=* delims= " %%a in ('powercfg /getactivescheme') do msg * %%a
    

    A better example using VBScript MsgBox, which can have custom title and icons:

    @echo off
    for /f "tokens=* delims= " %%a in ('powercfg /getactivescheme') do set "body=%%a"
    echo MsgBox "%body%",64,"YOUR TITLE" >temp.vbs
    cscript //nologo temp.vbs
    del temp.vbs
    

    Learn more on VBScript MsgBox