3

I cannot get this to work no matter what I do. Even if I drop the "msg /server: " syntax in a BAT file and call it from the Shell.Run, it still says "'msg' is not recognized as an internal or external command, operable program or batch file."

I've also tried "msg.exe" and "c:\windows\system32\msg.exe". All forms work fine from a CMD console direct entry, and from a VBScript or CMD/BAT script, but not from an HTA. Is that a security feature "by design"? Is there anyway around this?

Amicable
  • 3,115
  • 3
  • 49
  • 77
Skatterbrainz
  • 1,077
  • 5
  • 23
  • 31

1 Answers1

4

For backward compatibility, 64-bit Windows ships with two versions of MSHTA.exe:

  C:\Windows\SysWOW64\mshta.exe and 
  C:\Windows\System32\mshta.exe

The behavior you describe is one of the curiosities about the 64-bit MSHTA.exe, it can't invoke 32-bit applications like MSG.exe. Note that the 64-bit command prompt at c:\windows\SysWOW64\cmd.exe will also fail to find MSG.exe.

To fix this, you can associate .hta files with the 32-bit MSHTA.exe, or create a simple batch file to start your HTA, START_MSG.cmd:

START C:\Windows\System32\mshta.exe C:\YOUR_PATH\MSG.hta

I've tested the HTA below with both the 64 and 32-bit versions of MSHTA.exe. The 64-bit version raises a "file not found" error, but the 32-bit version works.

<script language="Javascript">
var E, LineWriteTimerID
function execWithStatus(cmdLine){ 
    E = new ActiveXObject("WScript.Shell").Exec(cmdLine);
    LineWriteTimerID = window.setInterval("writeOutLine()",100); 
    E.StdIn.Close();  
}
function writeOutLine(){
    if(E.StdOut.AtEndOfStream) window.clearTimeout(LineWriteTimerID);
    if(!E.StdErr.AtEndOfStream) txtResults.value += "ERROR: " + E.StdErr.ReadAll() + "\n";
    if(!E.StdOut.AtEndOfStream) txtResults.value += E.StdOut.ReadLine() + "\n";
}
</script>
 <textarea id=txtCmd style="width:90%" rows=1>MSG.exe</textarea> 
 <button onclick="execWithStatus(txtCmd.value)">Run</button>
 <br><textarea id=txtResults style="width:100%" rows=20></textarea> 
Rich
  • 268
  • 2
  • 5