PLC calls .bat to implement the versatile Windows command

At the beginning of the year, a customer wanted to have the PLC switch the Windows system to sleep. Today, another customer wanted to use the PLC to delete a folder. I found a universal solution: creating a .bat file that can execute almost all Windows cmd commands.Any task that can be completed in the cmd window can be completed by calling the .bat file with the PLC.

Keyword:

bat, NT_StartProcess

Methodology

1. Create a .bat file

Use Notepad to edit the command and save it as a .bat file.For example:

REM The following command deletes a folder, where /q indicates that a confirmation message window will not pop up

rd/s/q D:\Temp

2. Call the .bat file

Copy the. bat file to the controller where the PLC is located, and then call the function block NT in the PLC program_ StartProcess, and fill in the correct path and .bat file name.For example:


Note: Using NT_StartProcess requires referencing the library Tc2_Utilities