2

Working principle: when a button on HMI (Human Machine Interface) is pressed, it will open an external program. If the same button is pressed again, it will close the program. It works like a flip-flop command. If I use the command "StartProgram", it opens the program, but I don't know how to close the program. I sought a command like "StopProgram" or "CloseProgram", but I wonder it doesn't exist.

So, I'm trying to make this works through a code I've seen on the internet, but unsuccessfully. Below, my code:

Dim PCI
Set PCI = CreateObject("WScript.Shell")

If SmartTags("Flag Abrir PCI") = 1 Then
    PCI.Run """C:\pret\PCI.exe"" -p1 -c"
End If

If SmartTags("Flag Abrir PCI") = 0 Then
    PCI.Run "taskkill /F /IM PCI.exe", , True
End If

Could anyone give me a tip to make it work, please?

When I only write the code below, it opens, but don't know how to close it.

StartProgram "C:\pret\PCI.exe", "", hmiShowNormal, hmiNo
user692942
  • 16,398
  • 7
  • 76
  • 175
  • This is not standard VBScript it WinCC, the `StartProgram` command is proprietary to that system. See [the documentation](https://support.industry.siemens.com/cs/mdm/109096785?c=69073381515&dl=en). – user692942 Mar 25 '22 at 08:42
  • From the documentation it suggests you should use [`StopRuntime`](https://support.industry.siemens.com/cs/mdm/109096785?c=69073518603&lc=en-GB) to stop the program running on the device. – user692942 Mar 25 '22 at 08:44
  • WinCC Advanced, Professional or 7.x? – Cliff Pennalligen Mar 25 '22 at 11:44

2 Answers2

0

The code you have posted is proprietary code used by WinCC Professional which is a Siemens product. See the Official Documentation for more information.

Just from a brief look through the documentation, it looks like the StopRuntime command is what you are looking for.

Exits the runtime software and thereby the project running on the HMI device.

StopRuntime hmiStopRuntime
user692942
  • 16,398
  • 7
  • 76
  • 175
-1

Can you try something like below.

Set S = CreateObject("WScript.Shell")
Set X = S.Exec("C:\\pret\\PCI.exe")

'DO SOMETHING

'Closing, Status 0 indicates the executable is still running.
If X.Status = 0 Then X.Terminate()
Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34