#1 2021-02-25 06:01

pstein
Member
Registered: 2006-10-28
Posts: 41

"Msg" command not executable from Batch script

Assume I setup a Batch script which should be executed after a time of inactivity. Lets say after 2 minutes

The script file test.bat contains simplified the following code (replace "Peter" by your on user name):

cls
@echo off

echo [%TIME%] Trigger from Shutter


msg Peter /TIME:0 Timeout message

:end
pause

This script works when executed outside of Shutter by manual double click (in Win7).

If triggered by Shutter the echo command is written but the "Msg" popup message box cannot be shown.

Why?

I guess its a bug.
Can you fix it.

Thank you
Peter

Last edited by pstein (2021-02-25 06:05)

Offline

#2 2021-02-25 13:19

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,370

Re: "Msg" command not executable from Batch script

It is not a bug. This is how Windows works, unfortunately.

The whole problem stems from having two separate environments, 32-bit and 64-bit, which have different sets of utilities. One such difference concerns the "msg.exe" tool, which is only provided for the 64-bit environment.

When you start CMD (Command Prompt) on a 64-bit Windows, it will normally start a 64-bit version of CMD. However, Shutter is a 32-bit application, so when Shutter starts CMD, you will get a 32-bit version of CMD. 32-bit and 64-bit versions of CMD may use different environment paths and may have access different sets of utilities.

To put it simply, CMD cannot find the "msg.exe" tool when it is running in 32-bit mode. That is why you will see the following message:

'msg' is not recognized as an internal or external command, operable program or batch file.

You have two options:

1. Copy "msg.exe" tool from "%SystemRoot%\System32\msg.exe" to "%SystemRoot%\SysWOW64\msg.exe".
2. Use "%SystemRoot%\Sysnative\msg.exe" instead of just "msg.exe", to gain access to a 64-bit executbale from within a 32-bit environment.

Try amending your batch file as follows, and call it from Shutter:

%SystemRoot%\Sysnative\msg.exe * Test message

Beware, this command will only work if called by a 32-bit application in a 64-bit operation system.

For the reference:
Stack Overflow: I cannot use the msg command in cmd
Microsoft Docs: File System Redirector

Offline

Board footer

Powered by FluxBB