×
Siemens Industry Online Support
Siemens AG
SiePortal
Entry type: Application example Entry ID: 2976503, Entry date: 09/23/2003
(0)
Rate

Starting and closing a Windows program from WinCC

  • Entry
  • Associated product(s)

QUESTION:
How can I close a Windows program when I am in the Runtime of WinCC?

ANSWER:
You can close a program using Win32 API functions:

  • The "SendMessage" function sends the command to a process to close and waits until this command has been executed. Then it returns to the calling script.
  • The "PostMessage" function also sends the command to a process to close, but returns immediately to the calling script without waiting until the command has really been executed.
  • The "TerminateProcess" function removes the process from the main memory. The effect is the same as if you were to click the "End task" button in the Windows NT Task Manager.

Warning !:
Data might be lost if you use the "TerminateProcess" function. The data that the program is currently processing cannot be saved.
With the "SendMessage" and "PostMessage" functions the programs have a chance to close down properly your connections to databases, OPC services DLLs etc.
Therefore always use the "SendMessage" and "PostMessage" functions.

The following WinCC project shows how you can terminate the standard Windows program "Calculator". In the start window you see five buttons. You start the program with the "Start Calculator" button. With the "Close Calculator terminate", "Close Calculator SendMessage" and "Close Calculator PostMessage" buttons you close all "Calculator" programs running on the PC.

The script for the "Close Calculator" button is divided into the following elements:

  1. The handle to the "Calculator" window is determined from the window class name. The name of the class for the calculator window is "SciCalc".
    Note:
    You can find out the name of a window class using "Spy++". "Spy++" is included in the delivery package of Microsoft VC++ for example.
  2. The ID for the associated process is determined.
  3. A handle to the process is generated.
  4. The process is closed.

For the functions "sending message" and "mail message" the items 2 and 3 are dropped.

Note:
Below you can find one example project for SIMATIC WinCC V5.x and SIMATIC WinCC V6.0. The functionality of the two examples is identical.

The file "end_task.exe" contains a WinCC project. The project has been created with WinCC V5.0 SP1.

end_task.exe

Download the file and extract the project in a directory by double clicking . Open and continue to work on it with WinCC afterwards. Specify the computer name first.

The file "end_task_V6.exe" contains the WinCC project. The project has been created with WinCC V6.0.

end_task_V6.exe

Download the file and extract the project in a directory by double clicking. Open and continue to work on it with WinCC afterwards. Specify the computer name first.

Keywords:
Process handling, task administration

Security information
In order to protect technical infrastructures, systems, machines and networks against cyber threats, it is necessary to implement – and continuously maintain – a holistic, state-of-the-art IT security concept. Siemens’ products and solutions constitute one element of such a concept. For more information about cyber security, please visit
https://www.siemens.com/cybersecurity#Ouraspiration.
Rate entry
no rating
Requests and feedback
What do you want to do?
Note: The feedback always relates to the current entry / product. Your message will be forwarded to our technical editors working in the Online Support. In a few days, you will receive a response if your feedback requires one. If we have no further questions, you will not hear from us.