Open/Close an external program

1.5k views Asked by At

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
2

There are 2 answers

0
user692942 On

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
0
Pavan Chandaka On

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()