Albert F D
Albert F D

Reputation: 529

Batch - CMD.exe /T parameter option not setting colors as expected

In the absence of msg.exe on my OS, I'm trying to imitate the pop-up message box using cmd.exe. But what I've encountered is bugging me senseless.

My ultimate goal is to programmatically, using a .vbs script and schtasks.exe create a pop-up reminder in the Task Scheduler.

The issue I have, is if I run the following in a batch file:

start "Alert" cmd.exe /t:f0 /k "mode con: cols=40 lines=10 & echo *** Message goes here *** & echo. & echo. & echo. & echo. & echo. & echo. & echo. & echo Press any key to exit & pause>nul"

I get the desired outcome, however, if I change the /k parameter to /c (as intended in the original script) the selected foreground/background colors fail to display correctly...

I get around this by changing the script to:

start "Alert" cmd.exe /c "mode con: cols=40 lines=10 & color f0 & echo *** Message goes here *** & echo. & echo. & echo. & echo. & echo. & echo. & echo. & echo Press any key to exit & pause > nul"

But I don't understand why the /t fails in my original script. Could someone explain?

As a related question - not sure if this is permitted, in which case ignore - Task Scheduler allows the manual creation of a "Display a message" action, is this achieved within the application itself? and is it possible to set it programmatically via schtasks.exe?

Upvotes: 5

Views: 1590

Answers (1)

Jonathan
Jonathan

Reputation: 7561

Regarding cmd.exe ignoring /t when specifying /k - indeed that seems like a cmd.exe bug, I can confirm on a Windows 10 release 1607. Don't hold your breath for a fix...

Regarding schtasks.exe - there are some scheduled task features you can't create directly via command-line params. As a workaround, you can create such a task manually, export it, maybe edit the exported xml, and then re-create it using schtasks /Create /XML mytask.xml. Beware that Display a message is stated as (deprecated), so it may not work in future versions.

Upvotes: 4

Related Questions