Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I cannot use the msg command in cmd (or batch for that matter). How can I fix this?

While in cmd or making a batch file, I cannot use the command msg. When I try to use it, it returns the error msg is not recognized as an internal or external command, operable program or batch file." I'm pretty sure the error is that im missing a msg.exe in system32, so could someone show how to obtain that? I'm running windows 8.1.

like image 240
Levi Avatar asked Jun 22 '15 05:06

Levi


2 Answers

msg.exe is not available on all Windows platforms in all environments.

There is just %SystemRoot%\System32\msg.exe (64-bit), but no %SystemRoot%\SysWOW64\msg.exe (32-bit) on Windows 7 x64 Enterprise whereby 64-bit msg.exe must be accessed from within a 32-bit command process by using %SystemRoot%\Sysnative\msg.exe.

For details about System32, SysWOW64 and Sysnative see the Microsoft documentation page File System Redirector.

What does this mean?

  1. A batch file being executed on 32-bit Windows needs to run %SystemRoot%\System32\msg.exe.

  2. A batch file being executed on 64-bit Windows by 64-bit cmd.exe needs to run %SystemRoot%\System32\msg.exe.

  3. A batch file being executed on 64-bit Windows by 32-bit cmd.exe needs to run %SystemRoot%\Sysnative\msg.exe.

It depends on architecture of parent process starting cmd.exe or the batch file which implicitly results in starting cmd.exe for execution of the batch file if the batch file is executed in 32-bit or 64-bit environment on 64-bit Windows.

So a batch file is called with using explicitly %SystemRoot%\Sysnative\cmd.exe from a 32-bit application on Windows x64 or inside the batch file %SystemRoot%\Sysnative\msg.exe is used on a Windows x64 machine while on a Windows x86 machine %SystemRoot%\System32\cmd.exe respectively %SystemRoot%\System32\msg.exe must be used.

Demo example for first variant with using 64-bit command line interpreter:

Batch file with name MsgDemo.bat:

@echo off
%SystemRoot%\System32\msg.exe /?
pause

is called from 32-bit process running on Windows x64 with:

%SystemRoot%\Sysnative\cmd.exe /C MsgDemo.bat

Demo example for second variant with referencing msg.exe correct:

@echo off
set "AppMsg=%SystemRoot%\System32\msg.exe"
if not "%ProgramFiles(x86)%" == "" (

    rem Explicitly reference 64-bit version on Windows x64 as there is
    rem no 32-bit version. But use Sysnative redirector only if the batch
    rem file was started with 32-bit cmd.exe as otherwise System32 contains
    rem msg.exe if it is not missing at all like on Windows 7 Home Premium.

    if exist %SystemRoot%\Sysnative\* set "AppMsg=%SystemRoot%\Sysnative\msg.exe"
)
%AppMsg% /?
set "AppMsg="
pause

The redirector %SystemRoot%\Sysnative doesn´t exist for 64-bit processes, just for 32-bit processes.

%SystemRoot%\Sysnative is not a directory. Therefore if exist %SystemRoot%\Sysnative does not work, just if exist %SystemRoot%\Sysnative\*.

like image 88
Mofi Avatar answered Sep 26 '22 01:09

Mofi


Copy msg.exe from any windows 7 PC from system32 and past target PC system32 directory.

Work fine for me

like image 35
Ragu. M Avatar answered Sep 23 '22 01:09

Ragu. M