Press ESC to close · Ctrl+K to open

WinCC #ifdef RUN_ON_WEBNAVIGATOR

WinCC #ifdef RUN_ON_WEBNAVIGATOR

Normally, we will use this code when we want to take advantage of the same synoptic/function in WinCC and WebNavigator, but for some reason, there is an exception to use this function.
I will propose the following example, a button that will serve to log into our system and at the same time this button, if we are in WebNavigator, will serve to log out.

This is the testing synoptic with its button and its code


In our button, we will implement the described code and as in each conditional a different function is executed


Here is the code to copy ;-) and adapt according to needs

Code
#ifdef RUN_ON_WEBNAVIGATOR

	#pragma code ()
	#include "PWRT_api.h"
	#pragma code();
	PWRTLogout();

#else

	#pragma code("useadmin.dll")
	#include "PWRT_api.h"
	#pragma code()
	PWRTLogin('c');

#endif


If we run the runtime and test our button, we invoke the login function and here is the screen


If, on the contrary, we have run the WinCCViewerRT, by default we are already logged in, so if we press the button...


We log out and we can log back in with the same user or a different one. However, the configuration file must be without a default user ;-)

And if we talk about programming in VBScript, we have the function IsWebNavigator that will serve the same purpose.

Code
If IsWebNavigator() Then
	Msgbox("I am in Web Navigator")
Else
	Msgbox("I am NOT in Web Navigator")
End If