Display Current Logged-In User on WinCC Flexible HMI Panels
Engineers commissioning Siemens panels in WinCC Flexible 2008 or WinCC Flexible 2005 frequently need to expose the currently logged-in operator to the connected PLC so that recipe edits, parameter changes, alarm acknowledgments, and audit-trail entries can be recorded against a specific user account. WinCC Flexible already maintains a complete local user administration database, but the runtime does not automatically mirror that state to the controller. This guide documents a working scheduler-driven VBScript pattern, the underlying HMI-to-PLC tag architecture, the cause of the most common SmartTags("System\LOGIN_NotLoggedIn") compile error, and the alternate single-bit boolean status approach for projects with very limited tag budgets. Every function name, event name, and parameter is consistent with the WinCC Flexible runtime help and the system manuals listed in the Siemens Industry Online Support portal at support.industry.siemens.com.
1. Problem Statement and Use Cases
Operator audit trails on machine HMIs typically require three pieces of runtime data from the HMI:
- Current user name (string, 24 characters maximum in WinCC Flexible user administration)
- Login state (boolean: 1 = authenticated, 0 = not authenticated)
- Privilege level or group membership (numeric 0 to 9, derived from the user record's group number)
The reference script posted in the field report uses a scheduler-triggered VBScript that reads the runtime user with GetUserName, conditionally calls Logon to enforce a baseline authentication, and writes a single status bit back to the controller. That pattern is a viable starting point but contains a logic inversion and a tag-path issue that the rest of this article resolves. Engineers should use this guide to:
- Configure a complete HMI-to-PLC tag set covering both string and boolean state.
- Bind a scheduler task to the User change event so the script runs only when needed.
- Resolve the
"LOGIN_NotLoggedIn"compile error caused by an unresolved tag reference. - Implement the minimal one-bit pattern for controllers with no spare string-capable data blocks.
- Validate the result with a hands-on test procedure that exercises the login, logout, and default-user transitions.
2. System Architecture
The HMI panel is the authentication authority. WinCC Flexible stores user names, passwords, group numbers (0 = no rights, 1 to 9 = increasing privilege), and logoff timeouts in a local encrypted file on the panel. The PLC does not store user data; it only receives a snapshot of the active state through standard cyclic tag polling.
The PLC receives the data through an area pointer configured in the connection table. For a 24-character username on an S7-300/400, allocate a contiguous block of 12 words (each word holds two ASCII characters in S7 string-by-char convention) or 24 bytes when using S7-1200/1500 with the String data type. A single bit for the boolean status requires one M-bit or one DBX bit.
3. Prerequisites
Before writing any code, confirm the following:
- Software: WinCC Flexible 2008 SP3 (or matching version of 2005/2007) installed with the ES (engineering station) license. The PC Runtime is acceptable for bench testing.
- Panel image: A compatible panel image for the target device (TP177, TP277, MP377, etc.) must be installed via the ProSave tool or directly through WinCC Flexible.
- PLC connection: A configured MPI/Profibus/TCP connection in the WinCC Flexible project. For S7-1200/1500 over Ethernet, enable Permit access with PUT/GET on the controller (TIA Portal: Properties > Protection).
-
User administration enabled: In the project, open the runtime settings and confirm User administration is active. Without this,
GetUserNamereturns an empty string and the script will perpetually trigger the default-login branch. - A test PLC tag block: A DB or Merker area large enough to host a 24-byte string plus a byte for status bits.
4. HMI Tag and User Administration Configuration
Open the project, then complete the tag setup before writing the script. The script cannot compile unless the tags it references exist in the project dictionary.
| Tag Name | Type | Length | Connection / Area Pointer | Purpose |
|---|---|---|---|---|
UserName |
String | 24 | DB100.DBString[0..23] or MW100..MW123 | ASCII username written by the script |
UserState_LoggedIn |
Bool | 1 | DB100.DBX24.0 | 1 = real user, 0 = no one / default |
UserState_Group |
Uint | 16 | DB100.DBW26 | Numeric group 0 to 9 (privilege level) |
UserState_Heartbeat |
Bool | 1 | DB100.DBX28.0 | 1 Hz toggle for PLC to detect a dead HMI |
Create a user administration group with at least three records so the script can be tested against empty, default, and authenticated states:
| User Name | Password | Group | Logoff Timeout (min) |
|---|---|---|---|
| NoUser | default | 0 (no rights) | 0 (never) |
| Operator | op1234 | 3 (operator) | 15 |
| Maintenance | m-9876 | 7 (maintenance) | 30 |
The NoUser record is the placeholder user the script will log in automatically when no operator is authenticated. Group 0 holds no privileges, so the PLC can safely show machine status without allowing recipe edits.
5. Scheduler Event Configuration
Right-click Schedules in the project tree and add a new task named UserStatusSync. Two event triggers are useful in combination:
- Event: User change. Located under the system events. Fires every time a login, logoff, or user-switch occurs. This is the primary trigger for the script.
- Event: 1 s cyclic. Added as a secondary watchdog. It compensates for any missed events and guarantees the PLC state is refreshed after a panel reboot.
For each event, assign the same VBScript function (see section 6). Do not run the script on every value-change of a tag; the user-change event is the correct semantic anchor and avoids unnecessary PLC traffic.
6. VBScript Implementation
The corrected version of the original script addresses three issues: the tag path syntax, the logic inversion of the status bit, and the silent loss of the username string. The full working script is below.
'==========================================================
' File: UserStatusSync.vbs
' Project: WinCC Flexible 2008 SP3
' Trigger: Scheduler -> User change AND 1 s cyclic
'==========================================================
Option Explicit
Dim sUser, sDefaultPwd, sDefaultName, iGroup, sHeartbeat
sDefaultPwd = "default" ' Password for the NoUser placeholder
sDefaultName = "NoUser" ' Username of the placeholder record
' --- Step 1: Read the current operator --------------------
GetUserName sUser
If Len(sUser) = 0 Then
' No one is logged in -> force a baseline login so the
' panel never operates with an undefined operator.
Logon sDefaultPwd, sDefaultName
sUser = sDefaultName
End If
' --- Step 2: Look up group membership ---------------------
iGroup = GetUserGroup(sUser) ' Returns 0..9
' --- Step 3: Push state to the PLC ------------------------
SmartTags("UserName") = sUser
SmartTags("UserState_Group") = iGroup
' Inverted bit: 0 = real user authenticated, 1 = no one
If sUser = sDefaultName Then
SetBit SmartTags("UserState_LoggedIn")
Else
ResetBit SmartTags("UserState_LoggedIn")
End If
' --- Step 4: 1 Hz heartbeat for PLC dead-man detection ----
If SmartTags("UserState_Heartbeat") = 0 Then
SetBit SmartTags("UserState_Heartbeat")
Else
ResetBit SmartTags("UserState_Heartbeat")
End If
Key differences from the original posting:
-
SetBitandResetBitnow target the boolean tagUserState_LoggedIndirectly, without aSystem\prefix that was not present in the project dictionary. - The status bit is named for the positive condition (LoggedIn) and reset to 0 when a real operator is present, which is the convention used by S7 logic in the rest of the plant.
- The username is written as a string to
SmartTags("UserName")so the PLC receives the full identity, not just a flag. - A heartbeat toggle is added so the PLC can detect a frozen or disconnected HMI within one second.
7. Resolving the LOGIN_NotLoggedIn Compile Error
The original posting reports a compile error on the line SmartTags("System\LOGIN_NotLoggedIn"). The two most likely causes, in order of probability, are:
| Symptom | Root Cause | Fix |
|---|---|---|
| Compiler error: "Variable not defined" or "Expected: =" | The tag LOGIN_NotLoggedIn does not exist, or it exists but is not a boolean (SetBit/ResetBit require a Bool-type external or internal tag). |
Open Tags -> Project Tags and verify the name. If the tag is in a sub-folder named System, the access path is SmartTags("System\LOGIN_NotLoggedIn"); otherwise use SmartTags("LOGIN_NotLoggedIn"). |
| Compiler error: "Object required: 'user'" | Variable user is reserved in the VBScript environment on some service packs and conflicts with a property name. |
Rename the variable to sUser (as in the corrected script) and redeclare with Option Explicit. |
| Runtime error after compile: tag value never changes | The tag is internal-only and not linked to a PLC address. The script writes to the internal image, but the PLC never sees the bit. | Open the tag properties, switch to the Properties tab, and assign a PLC address such as DB100.DBX24.0. Confirm with the Tag Simulator in the project that the bit toggles. |
8. Boolean-Only Status Display (Single-Bit Pattern)
When the PLC has no free string-capable data block and the application only needs a single bit ("is a real operator logged in right now?"), the script collapses to the minimal form below. Place it in a scheduler task triggered by User change; the cyclic trigger is not required for this pattern.
' Single-bit pattern: 1 = real user, 0 = no one / default
Option Explicit
Dim sUser
GetUserName sUser
If Len(sUser) > 0 And sUser <> "NoUser" Then
ResetBit SmartTags("UserState_LoggedIn")
Else
SetBit SmartTags("UserState_LoggedIn")
End If
The PLC logic for a recipe-edit enable line then becomes a single bit test, for example in SCL/ST:
// S7-1500 SCL on DB100.DBX24.0 (UserState_LoggedIn)
IF "DB100".UserState_LoggedIn = FALSE AND "DB100".UserState_Group >= 3 THEN
bAllowRecipeEdit := TRUE;
ELSE
bAllowRecipeEdit := FALSE;
END_IF;
To expose the same state to a third-party device that only consumes GSD/EDS-style data, also publish the bit to a Modbus holding register using the Modbus TCP/IP area pointer available in WinCC Flexible 2008 SP1 and later (channel: Modicon Modbus TCP/IP).
9. PLC Program Reference (S7-1200/1500 in TIA Portal)
On the controller side, allocate a global DB to mirror the HMI data block. The block should be marked as non-optimized in TIA Portal so the HMI can access individual bytes and bits by absolute address, or keep it optimized and expose each element with the Accessible from HMI attribute.
// DB100 "HMI_UserStatus" - TIA Portal V15.1+
TYPE HMI_UserStatus :
STRUCT
sUserName : String[24]; // bytes 0..25 (2 byte header + 24 chars)
bUserLoggedIn : Bool; // byte 26.0
bUserHeartbeat : Bool; // byte 26.1
iUserGroup : Int; // bytes 28..29
END_STRUCT
END_TYPE
DATA_BLOCK "HMI_UserStatus"
{ S7_Optimized_Access := 'FALSE' }
VERSION : 0.1
NON_RETAIN
STRUCT
sUserName : String[24]; // initial := ''
bUserLoggedIn : Bool;
bUserHeartbeat : Bool;
iUserGroup : Int;
END_STRUCT
END_DATA_BLOCK
Add a heartbeat supervision OB (or use the existing cyclic OB1) that raises an HMI-fault bit if the heartbeat toggle does not change for more than 3 s. This is the cheapest way to satisfy the IEC 61131 requirement for fail-safe operator-station detection.
10. Verification Procedure
After the project has been compiled and downloaded to the panel, walk through the following sequence with the panel in Online mode and a tag monitor open in the PLC (online watch table on the DB):
- Power-cycle the panel. The script should run on the User change event triggered by the initial state. Confirm that
sUserNamereads'NoUser'andbUserLoggedIn = TRUEwithin 2 s of boot. - Log in as
Operator / op1234from the panel. The User change event must fire, and within 500 ms the DB must showsUserName = 'Operator',bUserLoggedIn = FALSE, andiUserGroup = 3. - Log out. Confirm the system auto-logs in
NoUserand the bit returns toTRUEwithiUserGroup = 0. - Wait 60 s and observe the heartbeat bit toggle. The PLC should see a transition at least once per second.
- Disconnect the Ethernet cable. Within 3 s, the PLC should raise the HMI-fault bit and disable all recipe-edit operations.
Repeat steps 1 to 5 with the panel in Runtime mode on the engineering PC (WinCC Flexible RT) to confirm the same behavior in both targets. The HMI behavior is identical across physical panels and PC Runtime, but the on-line tag monitor on the PC side is more convenient for capturing transitions.
11. Migration Path to TIA Portal (WinCC V11+)
Projects that started in WinCC Flexible are migrated to TIA Portal with the Migrate project wizard. The tag names, scheduler events, and scripts are carried over, but the API surface changes:
-
SmartTags("X")is replaced bySmartTags("X")in VBScript for the unified comfort panel and byHmiRuntime.SmartTags("X")for the WinCC Unified runtime. -
SetBit / ResetBitremain valid for boolean tags. -
GetUserNameis replaced byHmiRuntime.ActiveUser.Namein WinCC Unified V16+. See the Siemens Industry Online Support entry support.industry.siemens.com for the function-name mapping table. - Area pointers are configured per connection, not globally, and require the HMI tags editor to be in Absolute access mode.
The conceptual pattern — scheduler task listening to user change, push state to PLC, single bit for boolean use cases — remains valid and is the recommended approach for new TIA Portal projects as well.
12. Troubleshooting Matrix
| Symptom | Likely Cause | Verification | Resolution |
|---|---|---|---|
| Script does not compile: Variable not defined | Tag not in project dictionary | Open Project Tags and search | Create the missing tag, or correct the SmartTags path |
| Script compiles but tag value stays 0 | Tag is internal and not linked to PLC | Watch the tag in the HMI tag simulator | Assign a PLC address in tag properties |
GetUserName returns empty even when a user is logged in |
User administration is disabled in runtime settings | Check Runtime > User administration | Enable user administration and redownload the project |
| Username shown on PLC is truncated | PLC tag is too short | Watch the tag length in TIA Portal | Resize to String[24] and remap the area pointer |
| Heartbeat stops toggling after a few hours | Panel entered screen saver / standby | Check Screen saver settings | Increase the standby delay or move the scheduler to a non-suspendable task |
| PLC sees a stale user after network blip | Cyclic update was not retriggered | Inspect the scheduler task list | Add the 1 s cyclic trigger described in section 5 |
| Login attempt fails for valid operator | Password stored with different case or with leading / trailing whitespace | Edit the user in user administration and re-enter the password | Always re-enter passwords through the user-administration dialog, never by editing the exported file |
GetUserName instead of User.Identity.Name, and the data sink is a PLC tag rather than an HTML span.FAQ
How do I display the current logged-in user as text on a WinCC Flexible screen?
Create an HMI text field, link it to the UserName string tag, and on every User change event the VBScript in section 6 writes the active operator name to that tag. The panel displays the value as soon as the tag updates, typically within 100 ms of the login transition.
Why does the script fail to compile on the SmartTags line?
The most common reason is that the tag referenced inside the parentheses does not exist in the project dictionary, or its type is not Boolean for SetBit / ResetBit. Open Tags > Project Tags, confirm the exact name (including any folder prefix such as System\), and verify the data type. Avoid reserved VBScript identifiers like user for variable names.
Can I show the login state with a single bit instead of a full string?
Yes. Use the boolean-only pattern in section 8. The script writes a single bit to UserState_LoggedIn: 0 when a real operator is authenticated, 1 when the default NoUser placeholder is active. This is the most efficient option when the PLC has no free string data block.
What is the maximum username length in WinCC Flexible?
User names are limited to 24 characters in WinCC Flexible 2005/2007/2008. Allocate 24 bytes (plus a 2-byte S7 string header) for the PLC tag if you need full compatibility, or 16 bytes if your operator names are shorter and you want to save PLC memory.
How do I detect a disconnected or frozen HMI from the PLC?
Add a heartbeat bit to the script, as shown in section 6. The bit toggles every cycle. On the PLC side, start a timer (for example, IEC timer in OB1) whenever the bit changes; if the timer exceeds 3 s without a transition, raise an HMI-fault flag and lock out sensitive operations until the link is restored.
Does the same pattern work in TIA Portal WinCC?
Yes, the scheduler-and-tag pattern is preserved. Use HmiRuntime.ActiveUser.Name (WinCC Unified V16+) or the legacy GetUserName (Comfort panels V11 to V15) to read the operator, then write the value to the same set of PLC tags. Refer to the Siemens Industry Online Support portal at support.industry.siemens.com for the version-specific API mapping.