The above technique has a potential problem, in that if you are using UNC paths in your DEVICE statement in the MIAME.INI, the default working directory for the cmd.exe will be a UNC path (e.g. \\server\sharename\dsk0\123445).
It turns out that cmd.exe, by default does not allow running from a UNC directory, so it will spit out an error message and proceed to log to c:\windows, but in the process will probably fail to execute your command.
You can specify an explicit working directory in the
dir parameter of
MX_SHELLEX . But if you are using UNC paths and want to execute the target command from your current directory, that's not very convenient (since it isn't easy, or necessarily even possible, to convert a UNC path to a drive-letter equivalent).
Fortunately, this restriction in CMD.EXE can be disabled by setting the registry value HKCU\SOFTWARE\Microsoft\Command Processor\DisableUNCCheck
To do that programmatically:
map1 reg'value,b,4,1
map1 hkey'id,b,4
map1 status,f
xcall MIAMEX, MX_REGISTRY, REGOP_OPEN, HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Command Processor", &
RGKEY_SET_VALUE, hkey'id, status
xcall MIAMEX, MX_REGISTRY, REGOP_SET, hkey'id, "DisableUNCCheck", REG_DWORD, reg'value, status
Thanks goes to Jorge Tavares for discovering the problem and the solution, and sharing it!