External Commands for Windows 7

So I'm trying to setup several external commands and I think I'm missing a step here. I have scripts using powershell and can call them from a batch file. They work when selected in the folder and/or command prompt. I have made an 'extcommand.xml' document in 'C:\ProgramData\Repetier-Server\database'. I can see and select these options in Repetier Server, however nothing happens. I check the log and says 'Starting external command...' with no errors. I'm not sure how to follow the process after this. I'm guessing it's a permission issue since the scripts work and Repetier Server is recognizing the external commands. However, I'm not sure how to grant access to Repetier Server to run these external commands if that's the case. Perhaps it's something else? Anything is welcome.

sample extcommand.xml for reference:
<config>

<execute name="NAME" allowParams="true">c:\\FOLDER\\FILE.BAT</execute>

<command>
<name>NAME</name>
<execute>c:\\FOLDER\\FILE.BAT</execute>
<confirm>Really?</confirm>
</command>

</config>

Thanks

Comments

  • Bat files are maybe no executables. If you click them in explorer it knows to start them inside cmd.exe. I guess here you need to also start cmd.exe with the script as parameter.

    Do not think it is a permission issue, server under windows has quite high permissions.
  • you might be able to do a cmd.exe /c "c:\folder\bat.bat"
  • But please use full path to cmd.exe
  • Thanks for the quick response!

    Interesting you guys should mention that, I already have a FILE.cmd and have tried to open the command prompt and powershell applications first with a parameter. For some reason I cannot open any applications at all when run through RS. These commands work through Windows command prompt and powershell though. Any thoughts?

    c:\\windows\\system32\\windowspowershell\\v1.0\\powershell.exe "c:\\FOLDER\\FILE.cmd" or "c:\\FOLDER\\FILE.BAT"

    c:\\windows\\system32\\cmd.exe "..."
  • I am trying to do what was attempted in the comment above. I have a DOS batch file that I want to run using @execute, and can't figure out why it won't run in RS. Neither the Settings Command button, nor @execute commands work. This is my 1st attempt at trying to make it work.

    I have RS Free 1.2.1 connected USB to a Maker Select V2 printer.
    OS Name: Microsoft Windows 10 Home, Version: 10.0.19041 Build 19041, System Type: x64-based PC.

    Here's my C:\ProgramData\Repetier-Server\database\extcommands.xml:
    <config>
    <!-- Repetier Server service start credential was changed from Local to Owner (is admin user).
    Adds Repetier Server buttons under Settings (Gear Icon).
    If this file is changed, restart the Repetier Server service.
      -->
    <command>
    <name>Cmd1</name>
    <execute>"C:\\Windows\\System32\\cmd.exe C:\\Windows\\Notepad.exe"</execute>
    </command>
    <command>
    <name>Cmd2</name>
    <execute>"C:\\Windows\\System32\\cmd.exe"</execute>
    </command>
    <command>
    <name>Cmd3</name>
    <execute>"C:\\Windows\\System32\\cmd.exe C:\\CD\\webcamimagesave\\Test.bat"</execute>
    </command>

    <!-- Allows a G-Code command @execute Cmd<x> <params>. \\ are required in each command to make the command work.
    -->
    <execute name="Cmd1" allowParams="true">"C:\\Windows\\System32\\cmd.exe C:\\Windows\\Notepad.exe"</execute>
    <execute name="Cmd2" allowParams="true">"C:\\Windows\\System32\\cmd.exe"</execute>
    <execute name="Cmd3" allowParams="true">"C:\\Windows\\System32\\cmd.exe C:\\CD\\webcamimagesave\\Test.bat"</execute>
    </config>


    In the Settings (Gear icon) dropdown I have Cmd1, Cmd2, Cmd 3 buttons.
    Under Troubleshooting I have no errors listed.
    I click Cmd1, get [06.02.2022 10:46:27] : Handling action 'runExternalCommand' caused error System exception.
    I click Cmd2, get no errors, nothing else.
    I click Cmd3, get [06.02.2022 10:48:02] : Handling action 'runExternalCommand' caused error System exception.

    In the RS printer console window, with the printer on and connected, I send the @execute commands. In every case, Notepad does not start, no black CMD window flashes. Cmd1 and Cmd3 commands produce System Errors, the rest do not.
    @execute Cmd1, the response is Send:10:50:36.415: @execute Cmd1.
    System Error is [06.02.2022 10:50:36] : error:Printer::manageHostCommand:System exception

    @execute Cmd2, the response is Send:10:51:23.539: @execute Cmd2.
    @execute Cmd2 "C:\windows\notepad.exe", the response is Send:10:53:09.060: @execute Cmd2 "C:\windows\notepad.exe".
    @execute Cmd2 "C:\\windows\\notepad.exe", the response is Send:10:55:03.916: @execute Cmd2 "C:\\windows\\notepad.exe".

    @execute Cmd3, the response is Send:10:57:21.211: @execute Cmd3.
    System Error is [06.02.2022 10:57:21] : error:Printer::manageHostCommand:System exception

    I've fought this for 8 hours, checking forum messages back 2 years, the FAQ, the RepRap forum, and most are Linux-related but only one Comment listed above was found to talk about my issue, and didn't have a resolution. Another Comment suggested Repetier Server service start credentials might be the issue, so it was changed from Local to Owner (is admin user). I've restarted the laptop, changed the extcommands.xml file and restarted RS Server many times, tried to run BAT and CMD and EXE files. The System Log doesn't shed any light on this, just repeating the System Errors seen in the Command window. I've checked that the commands work in a DOS command window. In RS I can't get a CMD window to popup or commands to run.

    It seems that Cmd2 holds the most promise since it doesn't produce a System Error. Any ideas on how to get the RS command buttons and @execute to run a Windows 10 program or batch file?
  • Please don't use those quotes around your commands. That will lead to invalid commands. Also if you want to pass through a parameter to cmd.exe please make sure to use the /C param before.

    <command>
    <name>Cmd1</name>
    <execute>C:\\Windows\\System32\\cmd.exe /C C:\\Windows\\Notepad.exe</execute>
    </command>

    Should work.


     
  • Repetier_Support thank you for the quick reply and suggestion.

    I changed my extcommands.xml as you suggested, revising the existing commands and executes, and adding a new Cmd4 copied and pasted from your example. With the printer powered on and no System Errors, Cmd1-4 did not produce any System Errors, but also didn't open Notepad or any other programs. In the RS Console>_ window, I tried @execute Cmd1
    @execute Cmd2 C:\windows\notepad.exe
    @execute Cmd2 "C:\windows\notepad.exe"
    @execute Cmd3
    None produced any System Errors, but also didn't open any programs.

    In Google Chrome I found an update was available, and updated Version 97.0.4692.99 (Official Build) (32-bit) to Version 98.0.4758.81 (Official Build) (32-bit). No change.

    Since I had a ghost Run Notepad button in my RS Console>_ Commands dropdown leftover from 1 of my attempts, and Server Log - Delete was red and didn't delete the log file, I downloaded the RS V1.21 EXE, exited RS, and installed it, restarted the laptop. No change.

    Here's my Server Log from when RS started:
    2022-02-07 12:02:45: Stopping lua runner ...
    2022-02-07 12:02:45: Stopping global cloud ...
    2022-02-07 12:02:45: Stopping open threads ...
    2022-02-07 12:02:45: Shutting down web server.
    2022-02-07 12:02:46: Prevent sleep thread stopped.
    2022-02-07 12:02:46: Closing server
    2022-02-07 12:02:46: Stopping work dispatcher.
    2022-02-07 12:02:46: Work dispatcher thread stopped.
    2022-02-07 12:02:46: Internal Work dispatcher thread stopped.
    2022-02-07 12:02:46: Waiting for all threads to finish ...
    2022-02-07 12:02:46: Worker threads finsihed.
    2022-02-07 12:02:46: Stopping printer threads.
    2022-02-07 12:02:46: Port closed for Monoprice Select V2
    2022-02-07 12:02:46: Connection closed: Monoprice Select V2
    2022-02-07 12:02:46: Printer thread for Monoprice_Select_V2 stopped
    2022-02-07 12:02:46: Printjob manager thread for Monoprice_Select_V2 stopped.
    2022-02-07 12:02:46: Closing user database.
    2022-02-07 12:02:46: Server is now down.
    2022-02-07 12:02:50: Start logging...
    2022-02-07 12:02:50: Imported external command Cmd1
    2022-02-07 12:02:50: Imported external command Cmd2
    2022-02-07 12:02:50: Imported external command Cmd3
    2022-02-07 12:02:50: Imported external command Cmd4
    2022-02-07 12:02:50: Imported allowed execute command Cmd1
    2022-02-07 12:02:50: Imported allowed execute command Cmd2
    2022-02-07 12:02:50: Imported allowed execute command Cmd3
    2022-02-07 12:02:50: Webdirectory: C:\Program Files (x86)\Repetier-Server\www\
    2022-02-07 12:02:50: Storage directory: C:\ProgramData\Repetier-Server\
    2022-02-07 12:02:50: Configuration file: C:\Program Files (x86)\Repetier-Server\bin\RepetierServer.xml
    2022-02-07 12:02:50: Directory for temporary files: C:\Users\Owner\AppData\Local\Temp\
    2022-02-07 12:02:50: Reading firmware data ...
    2022-02-07 12:02:50: Starting Network ...
    2022-02-07 12:02:50: Active features:0
    2022-02-07 12:02:51: Reading printer configurations ...
    2022-02-07 12:02:51: Reading printer config C:\ProgramData\Repetier-Server\configs\Monoprice_Select_V2.xml
    2022-02-07 12:02:51: Starting printjob manager thread for Monoprice_Select_V2
    2022-02-07 12:02:51: Starting printer threads ...
    2022-02-07 12:02:51: Starting printer thread for Monoprice Select V2
    2022-02-07 12:02:51: Starting work dispatcher subsystem ...
    2022-02-07 12:02:51: Starting user database ...
    2022-02-07 12:02:51: Importing projects ...
    2022-02-07 12:02:51: Initializing LUA ...
    2022-02-07 12:02:51: Register LUA cloud services
    2022-02-07 12:02:51: add G-Code-Renderer
    2022-02-07 12:02:51: LUA initalization finished.
    2022-02-07 12:02:51: Work dispatcher thread started.
    2022-02-07 12:02:51: Internal work dispatcher thread started.
    2022-02-07 12:02:51: Starting web server ... 
    2022-02-07 12:02:51: Prevent sleep thread started.
    2022-02-07 12:02:51: Webserver started.
    2022-02-07 12:02:54: Connection started: Monoprice Select V2
    2022-02-07 12:02:54: Internal reset printer Monoprice Select V2
    2022-02-07 12:02:54: Reset printer Monoprice Select V2
    2022-02-07 12:03:11: Websocket opened

    Do you think my RS install is corrupt? If so, should delete the RS folder and re-install it?

    I'm baffled as to what to try next.
  • How does your new extcommands.xml look like now? Hard to say what is wrong when we don't see your new version.
  • Here is extcommands,xml after revisions. I changed the @execute commands names from Cmd<x> to Exe<x> so as not to confuse them with the other commands. Didn't make any difference on running.
    <config>
    <!-- Repetier Server service start credential was changed from Local to Owner (is admin user).
    Adds Repetier Server buttons under Settings (Gear Icon).
    If this file is changed, restart the Repetier Server service.
      -->
    <command>
    <name>Cmd1</name>
    <execute>C:\\Windows\\System32\\cmd.exe /C C:\\Windows\\Notepad.exe</execute>
    </command>
    <command>
    <name>Cmd2</name>
    <execute>C:\\Windows\\System32\\cmd.exe /C C:\\CD\\webcamimagesave\\StartWebcam.cmd</execute>
    </command>
    <command>
    <name>Cmd3</name>
    <execute>C:\\Windows\\System32\\cmd.exe /C C:\\CD\\webcamimagesave\\Test.bat</execute>
    </command>
    <command>
    <name>Cmd4</name>
    <execute>C:\\Windows\\System32\\cmd.exe /C C:\\Windows\\Notepad.exe</execute>
    </command>

    <!-- Allows a G-Code command @execute Cmd<x> <params>. \\ are required in each command to make the command work.
    -->
    <execute name="Exe1" allowParams="true">C:\\Windows\\System32\\cmd.exe /C C:\\Windows\\Notepad.exe</execute>
    <execute name="Exe2" allowParams="true">C:\\Windows\\System32\\cmd.exe /C</execute>
    <execute name="Exe3" allowParams="true">C:\\Windows\\System32\\cmd.exe /C C:\\CD\\webcamimagesave\\Test.bat</execute>
    </config>

    I also found the Run Notepad command was one that I had created in the Console>_ Commands dropdown. Deleted it and it went away from the drop down as expected. The <trash can icon> Delete All text on the Server Logs page is still red and does not delete the logs.

    It would be great if there was somewhere I could see the output of the commands and executes being processed.
  • All notebook examples from your code work. Just copied it 1:1 and tested. Even
    @execute Exe2 C:\\Windows\\Notepad.exe
    did work for me.

    Did you restart server or windows after changing the file? It is only read on startup.
  • Yes, I closed the RS webpage, then stopped and started RS Server service after each change to extcommands,xml and then tested the commands and executes. That the commands and executes work on your Windows PC confirms that my extcommands,xml file is functional. If I make a syntax error in extcommands,xml, I get a Server Error complaint, so RS appears to be finding the file.

    I restarted the computer, opened RS >_Console, and pasted your tested command.
    Send window: @execute Exe2 C:\\Windows\\Notepad.exe
    Response: Send:13:13:28.592: @execute Exe2 C:\\Windows\\Notepad.exe
    No System Errors, but Notepad did not appear. I tried it 1st with the printer powered off, and again with the printer on.

    Here's some news! I then started Windows Task Manager, and Notepad was shown as Running in there 2 times, both under the Owner user, which is my Windows user name. So Notepad is running, but not visible! In TM I selected the 1st Notepad listing in the Background Processes section, right-clicked, selected Open File Location, it brought me to C:\Windows\notepad.exe as expected, and I double-clicked C:\Windows\notepad.exe and it opened normally. In TM the 3rd running Notepad showed up in the Apps section. I right-clicked Notepad, clicked on Properties, and all the listed Users (Owner is an Administrator) have Read and Execute permissions.

    So it looks like on my PC the Command in RS is starting Notepad as a Background Process, not as a App, so it's not visible. Is that right?

  • Interesting that it starts invisible. Server is running as admin so notepad is in deed started as administrator. I used my debug version so that might be, why I see it in foreground - it is not running as service.

    So you can start software just not software with gui. But that is actually what it is for anyway. To trigger processes not controllable from server directly that finish after a short while.
  • Repetier-Support - thanks again for the support.

    I tried a few more changes listed below, but overall, @execute commands do not work for me. In Sept 2020 I tried installing Cura as my printer server, which required Windows x64, so I loaded that. Had trouble with Windows graphics rendering, so I loaded Repetier Host, which loaded Repetier Server. I don't remember any installation issues with RH or RS, and they properly control my printer.

    I created a new short extcommands.xml stripping out all but Exe1. Restarted RS server, so the RS <gear icon> dropdown does not have any commands from extcommands.xml, as expected:
    <config>
    <execute name="Exe1" allowParams="true">C:\\Windows\\System32\\cmd.exe /C</execute>
    </config>

    After a PC restart, in RS >_Console window, sent these commands:
    @execute Exe1 C:\\windows\\notepad.exe --> Notepad did not open GUI, it is in Task Manager as a Background Process.
    @execute Exe1 C:\\windows\\mspaint.exe --> Paint did not open GUI, it is not in TM.
    @execute Exe1 copy C:\\CD\\Repetier service.bat C:\\CD\\Repetier service2.bat --> Did not make a copy of the file, nothing new in TM.
    @execute Exe1 "copy C:\\CD\\Repetier service.bat C:\\CD\\Repetier service2.bat" --> Did not make a copy of the file, nothing new in TM.

    Just for a test using a Windows 10 Pro x32 PC with no 3D printer attached, I downloaded and installed RS V1.2.1. Copied my new short extcommands from my x64 PC to C:\ProgramData\Repetier-Server\database\extcommands.xml. Created a new printer by downloading then uploading the printer configuration file into RS. Tried RS >_Console @execute Exe1 C:\\windows\\notepad.exe --> No System Errors, Notepad did not open GUI, it is in Task Manager as a Background Process. So the @execute command didn't work on my Windows x32 bit PC - of course the printer was offline, but the @execute command acted the same as on my x64 PC. And the Log File - <trash can icon> Delete All red text did not delete the Server Log. So maybe a Windows re-install to x32 on my x64 PC wouldn't fix this issue?

    Repetier-Support I can't imagine that @execute commands like mine don't show a visible Notepad GUI on other RS installations on Windows PC's, or you'd get requests for help. I'm still baffled.
  • I thought I found something, but it is just more analysis without a resolution that might help with diagnosis. On x32 and x64 Windows, there are 2 copies of Notepad.exe - one in C:\Windows\ and a 2nd in C:\Windows\System32\. So I tried running each one using the RS >_Command on my x64 PC with the printer online. 
    @execute Exe1 C:\\windows\\notepad.exe
    @execute Exe1 C:\\windows\\system32\\notepad.exe
    In Task Manager, there were 2 Background Processes listed, Notepad and Notepad (32 bit). However, neither Notepad opened a Notepad GUI. Right-clicking Notepad - Open file location brought me to C:\Windows\. Notepad (32 bit) brought me to C:\Windows\SysWOW64, not C:\Windows\System32\ as expected (there's a 3rd copy of Notepad.exe there). Running any of the Notepad.exe files in Explorer opens the Notepad GUI and it shows up in TM Apps as expected.

    Just so there's no confusion, as shown in TM, Notepad and Notepad (32 bit) are running as a Background Process, and do not appear in the Windows Services listing.

    For fun I tried @execute Exe1 C:\\windows\\system32\\mspaint.exe, and TM showed Paint (32 bit) running as a Background Process, but no Paint GUI.
  • I googled it a bit and the behaviour is correct, see
    https://stackoverflow.com/questions/5307968/how-can-i-run-an-exe-program-from-a-windows-service-using-c

    so as long as you start server as service it is not attached to a user and can not open desktop apps resp. they have no desktop to show up. This would only work if you start it within your regular desktop environment as desktop. Just stop the service and go to
    C:\Program Files (x86)\Repetier-Server\bin
    and start RepetierServer.exe - now they will be started as it is now running in desktop environment. Set service as start never if you want this solution permanently.


  • Repetier-Support thanks for the insight. I Googled about 20 web forums, and they all agreed that Windows 7 and above will not allow a Service to run a program GUI as a tightened security measure. A User needs to be logged in to see the GUI.

    I tried your suggestion to run RepetierServer.exe as a Console App, and as long as I opened RS with Admin rights, RS worked, as did Repetier Host. It opened a command window with about 30 lines, and RS appeared in Task Manager as a console App. Sending @execute Exe1 c:\\windows\\notepad.exe opened Notepad.exe as a Console App with it's GUI.

    So I'm set. Thanks again for finding a solution.
Sign In or Register to comment.