Running a DOS program from SYSTEM32 Directory

Started by officevision, January 19, 2022, 08:59:50 AM

Previous topic - Next topic

officevision

Good day to all!

It has been a long while since writing code and must admit I have gotten somewhat rusty. I am hoping I am just making a dumb mistake that will easily be seen and corrected here. I am trying to call the "msg.exe" program from the c:\windows\system32 directory and pass it some paramaters that are generated from a user filling in a dialog. For some reason, I get an error 1932 on every type of Run/RunShell/ExecuteShell etc. that I try which happens to be an error that does not give a lot of helpful information.

I also tried generating a "cmd" file and then running that file but get an error that the program I am trying to run is not recognized as an internal or external command, operable program or batch file which I think means I am not finding the executable for some reason. Below is the section of code with the different options I have tried. Any help would be appreciated.

:Sys_MSG
Debug(@ON)
   CmdFile = FileOpen("c:\wrapper\msgcmd.cmd", "Write")
   FileWrite(CmdFile, "@echo on")
   FileWrite(CmdFile, "c:\windows\system32\msg.exe /SERVER:%systemname% * /TIME:15 %messagetext%")
   FileWrite(CmdFile, "Pause")
   FileWrite(CmdFile, "Exit")
   FileClose(CmdFile)
   ShellExecute("msgcmd.cmd", "", "c:\wrapper", @NORMAL, "")
   ;Run("c:\windows\system32\msg.exe", "?")
   ;params = "/SERVER:%systemname% * /TIME:15 %messagetext%"
   ;RunShell("msg.exe", params, "c:\windows\system32", @NORMAL, @NOWAIT)
   ;Run("c:\windows\system32\msg.exe", "/SERVER:%systemname% * /TIME:15 %messagetext%")
   ;RunShell("msg.exe", "/SERVER:%systemname% * /TIME:15 %messagetext%", "c:\windows\system32", @HIDDEN, @NOWAIT)
   ;ShellExecute("msg.exe", "/SERVER:%systemname% * /TIME:15 %messagetext%", "", @HIDDEN, "")
Debug(@OFF)
   Return

td

The msg.exe executable is 64-bit only. You need to either run your script with 64-bit Winbatch or temporarily disable 32-bit file redirections. For more information on disabling file redirection see the documentation for the IntControl function option 92 in the Consolidated WIL Help file or online:

https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/WILAK_I__110.htm

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

One possible approach.

Code (winbatch) Select
messagetext = 'Hello World'
systemname = '**my workstation' ; Your system name here.
Cmd = Environment( 'ComSpec')
cd  = FilePath(Cmd)
IntControl( 92, 'Disable', 0,0,0)
ShellExecute("msg.exe", "/SERVER:%systemname% * /TIME:15 %messagetext%" , cd, @Normal, "")
IntControl( 92, 'Revert', 0,0,0)
exit


[edit] The setting the current directory and @Normal display mode are likely not necessary but are helpful for debugging purposes.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Neglected to mention that there is also the wtsSendMessage function in the Terminal Services Extender. This function allows you to send a message without "shelling out".

https://docs.winbatch.com/mergedProjects/TerminalServices/TERMSERVwtsSendMessage.htm
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

archimede

Do you tryed to manually launch the builded .cmd program from the same directory? If yes, and if it worked well, I builded for me function that works exactly like a command line.

officevision

Thank you all for the replys. TD - your reply was spot on. I incorporated your code and all is right with the world once again. Well.....

Anyway - thank you all agian!

Fred