Runtime Identification: Professional vs Advanced vs Panel
Before any VBScript is written, confirm which TIA Portal WinCC edition is in scope. The WinCC VBS programming model is shared across the WinCC family, but the tag-access syntax, file-system permissions, and storage locations differ in ways that will silently break a script that was authored for the wrong edition.
| Edition | Typical Hardware | Tag Access from VBS | Local Storage Path | OS Footprint |
|---|---|---|---|---|
| WinCC Professional (RT Professional) | PC (Windows 7 / Windows 10) | SmartTags("Name") |
C:\ProgramData\...\ or any local drive the Runtime service can read |
Full Windows |
| WinCC Advanced Runtime | PC (Windows 7 Embedded / W10) |
HMIruntime.Tags("Name") or SmartTags("Name") depending on version |
C:\ProgramData\Siemens\Automation\... |
Full Windows |
| WinCC Advanced on Comfort/MTP Panels | SIMATIC HMI TP/MTP | SmartTags("Name") |
\Storage Card2\... or /media/simatic/...
|
Windows Embedded Compact / Linux |
If the project is loaded on a PC with a true C: drive, the Runtime is almost certainly WinCC Professional (or RT Advanced on PC). Scripts written for a SIMATIC Panel must be retargeted because the file-system root, the trailing slash conventions, and the COM-object availability all change.
The two Siemens FAQ articles that anchor this topic are:
- Siemens FAQ 850338 - File access with VBS in WinCC V7.x / Professional
- Siemens FAQ 106501825 - File access with VBS on SIMATIC WinCC Panels / RT Advanced
The script syntax in FAQ 850338 is written for WinCC V7.2 but the same COM objects, the same Scripting.FileSystemObject calls, and the same SmartTags access pattern carry forward into WinCC Professional V13, V14, V15, V16, V17 and V18 unchanged. Newer TIA Portal versions add helpers but the V7.2-era code still runs.
Prerequisites
- TIA Portal V13 SP1 Update 9 (or any later V13.x) with WinCC Professional installed and licensed. The Professional option must be active - it is a separate license on top of TIA Portal.
-
WinCC RT Professional license on the Runtime PC, either a USB hardlock or a software key in
C:\Program Files (x86)\Siemens\Automation\SimaticLicenseManager. -
Windows user account that starts the WinCC Runtime service with read access to the target file. On a default install, the Runtime service starts under
SIMATIC HMIuser; that user must be grantedReadon the directory containing the .ini or .csv file. -
HMI tags already declared in the project for every value the script will write. VBS cannot create tags at runtime; missing tags raise
Smart Tagserrors in the WinCC diagnostics window and the value is silently dropped. - A startup event scheduled in the project scheduler that fires before any operator screen reads the tag. See the Wiring the Script to Runtime Startup section below.
C:\Program Files (x86)\..., the Runtime service often cannot read the file. Place .ini/.csv files under C:\ProgramData\Siemens\, C:\Recipes\, or any other ACL-controlled path where the Runtime account has read access.VBScript File Access Model in WinCC
WinCC Runtime exposes the standard Windows Script Host (WSH) object model. Two COM objects cover almost every file-handling use case:
| COM Object | ProgID | Purpose |
|---|---|---|
| FileSystemObject | Scripting.FileSystemObject |
Folder/file enumeration, exists checks, drive info |
| TextStream | Returned by FSO.OpenTextFile
|
Sequential read/write of UTF-8, ASCII, or Unicode text |
A minimal reading pattern:
Dim oFSO, oFile, sLine
Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists("C:\Recipes\Config.ini") Then
Set oFile = oFSO.OpenTextFile("C:\Recipes\Config.ini", 1, False, -1)
Do While Not oFile.AtEndOfStream
sLine = oFile.ReadLine
' parse sLine here
Loop
oFile.Close
End If
Set oFile = Nothing
Set oFSO = Nothing
The third argument to OpenTextFile is create-if-missing; pass False for read-only. The fourth argument is the format: -2 opens with system default encoding, -1 forces Unicode, 0 forces ASCII. For CSV files exported by Excel on a Western Windows install the safest default is -1 (Unicode), because Excel often prepends a BOM that confuses ReadLine under ASCII mode.
Reading an INI File - Procedure
An INI file is line-oriented with three line types:
-
[SectionName]- header line -
Key=Value- assignment -
; commentor blank - ignored
Step 1 - Add a project-wide VBS function
Open the project tree in TIA Portal, right-click Scripts > VBScripts, choose Add new function, and name it ReadINIValue. Paste the following implementation. It returns a default value when the key is missing, the file is missing, or the file cannot be parsed - this keeps Runtime startup robust against a missing recipe file.
Function ReadINIValue(ByVal sFile, ByVal sSection, _
ByVal sKey, ByVal sDefault)
Dim sResult, sLine, bInSection, iEq
Dim oFSO, oFile
On Error Resume Next
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Err.Number <> 0 Then
ReadINIValue = sDefault
Exit Function
End If
If Not oFSO.FileExists(sFile) Then
Set oFSO = Nothing
ReadINIValue = sDefault
Exit Function
End If
Set oFile = oFSO.OpenTextFile(sFile, 1, False, -1)
If Err.Number <> 0 Then
Set oFSO = Nothing
ReadINIValue = sDefault
Exit Function
End If
bInSection = False
Do While Not oFile.AtEndOfStream
sLine = Trim(oFile.ReadLine)
If Len(sLine) = 0 Then GoTo NextLine
If Left(sLine, 1) = "[" And Right(sLine, 1) = "]" Then
bInSection = (UCase(Mid(sLine, 2, Len(sLine) - 2)) = UCase(sSection))
ElseIf bInSection And Left(sLine, 1) <> ";" Then
iEq = InStr(1, sLine, "=", vbTextCompare)
If iEq > 0 Then
If Trim(Left(sLine, iEq - 1)) = sKey Then
sResult = Trim(Mid(sLine, iEq + 1))
Exit Do
End If
End If
End If
NextLine:
Loop
oFile.Close
Set oFile = Nothing
Set oFSO = Nothing
If Err.Number <> 0 Or Len(sResult) = 0 Then
ReadINIValue = sDefault
Else
ReadINIValue = sResult
End If
End Function
Step 2 - Call from a startup action
Add a second function LoadConfig that resolves the value and writes it to a tag. Casting to CInt forces the integer tag type required by the project:
Sub LoadConfig()
Dim sVal
sVal = ReadINIValue("C:\Recipes\Config.ini", "Runtime", "BatchSize", "100")
SmartTags("BatchSize") = CInt(sVal)
sVal = ReadINIValue("C:\Recipes\Config.ini", "Runtime", "LineSpeed", "0")
SmartTags("LineSpeed") = CInt(sVal)
End Sub
SmartTags(...) is a COM collection exposed by WinCC Professional. It returns a variant, so always cast with CInt, CStr, CDbl, or CBool before assigning; otherwise an empty INI value will propagate Empty into an INT tag and raise a quality-bad.Reading a CSV File - Procedure
CSV is preferred when the recipe list contains many rows or when the same data is shared with Excel, the MES layer, or another SCADA. The file format is:
TagName,Value,Comment
BatchSize,250,; primary recipe
LineSpeed,1200,; mm/s
TargetTemp,82,; degC
Step 1 - Add a CSV loader function
Sub LoadCSVTags(ByVal sFile)
Dim oFSO, oFile, sLine, arrFields, sName, sValue
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FileExists(sFile) Then
HMIRuntime.Trace("CSV missing: " & sFile & vbCrLf)
Set oFSO = Nothing
Exit Sub
End If
Set oFile = oFSO.OpenTextFile(sFile, 1, False, -1)
' skip header
If Not oFile.AtEndOfStream Then oFile.ReadLine
Do While Not oFile.AtEndOfStream
sLine = oFile.ReadLine
If Len(Trim(sLine)) = 0 Then GoTo NextRow
If Left(Trim(sLine), 1) = ";" Then GoTo NextRow
arrFields = Split(sLine, ",")
If UBound(arrFields) < 1 Then GoTo NextRow
sName = Trim(arrFields(0))
sValue = Trim(arrFields(1))
Select Case sName
Case "BatchSize"
SmartTags("BatchSize") = CInt(sValue)
Case "LineSpeed"
SmartTags("LineSpeed") = CInt(sValue)
Case "TargetTemp"
SmartTags("TargetTemp") = CInt(sValue)
Case Else
HMIRuntime.Trace("Unknown tag in CSV: " & sName & vbCrLf)
End Select
NextRow:
Loop
oFile.Close
Set oFile = Nothing
Set oFSO = Nothing
End Sub
Step 2 - Schedule the loader
Sub LoadCSVTags_Startup()
LoadCSVTags "C:\Recipes\Startup.csv"
End Sub
If the CSV contains quoted fields or commas inside values, replace the simple Split(sLine, ",") with a state-machine tokenizer. The simplest robust pattern is a tiny function that walks character-by-character and toggles an inQuotes flag whenever it sees a ":
Function SplitCSV(ByVal sLine)
Dim a(), n, i, ch, cur, inQ
ReDim a(10)
n = 0 : cur = "" : inQ = False
For i = 1 To Len(sLine)
ch = Mid(sLine, i, 1)
If ch = """" Then
inQ = Not inQ
ElseIf ch = "," And Not inQ Then
If n > UBound(a) Then ReDim Preserve a(n + 10)
a(n) = cur : n = n + 1 : cur = ""
Else
cur = cur & ch
End If
Next
If n > UBound(a) Then ReDim Preserve a(n)
a(n) = cur : n = n + 1
ReDim Preserve a(n - 1)
SplitCSV = a
End Function
Wiring the Script to Runtime Startup
The Sub only fires when something calls it. Tie it to Runtime startup using the WinCC scheduler:
- In the project tree expand Common data > Schedulers.
- Open Schedulers and add a new task. Set Trigger to Runtime start.
- Set Function list or Event to call
LoadConfig(INI) orLoadCSVTags_Startup(CSV). - Compile and download the project. Confirm the new task appears in the Runtime under System info > Schedulers.
Alternative: assign the function to a screen's Open event on the start screen if a single screen handles the load. This is less robust because if the operator changes start screens later the script is bypassed.
Differences for Advanced Runtime and Panels
The same VBS skeleton works, but several behaviors diverge. The table summarizes what changes when the same project is ported from a PC Runtime to a Comfort/MTP panel.
| Item | PC Runtime (Professional / Advanced) | Comfort / MTP Panel |
|---|---|---|
File root for C:\ paths |
OS drive letter, full ACL | Invalid - no C: drive exists. Use \Storage Card2\... or /media/simatic/...
|
| Tag access | SmartTags("X") |
SmartTags("X") (identical) |
| Max file size comfortable to parse at startup | ~50 MB (RAM available) | ~2 MB before noticeable startup delay |
| Encoding | Unicode / UTF-8 / ASCII all supported | Limited codepage support; force ASCII for non-Western alphabets |
| Write permission default | Runtime service has write under its profile | Read-only by default; SystemCF card may need enabling |
For panel targets the script body stays the same but the path constants change:
Sub LoadCSVTags_Panel()
LoadCSVTags "\Storage Card2\Recipes\Startup.csv"
End Sub
Siemens FAQ 106501825 documents the panel-specific file-system restrictions and gives a working snippet that uses HMIRuntime.FileSystem instead of raw Scripting.FileSystemObject when an OEM wants path validation.
File Path Conventions and Whitelisting
Modern TIA Portal versions (V15 and later, back-ported to V13 SP1 Update 9 through a hotfix) restrict script access to a configurable allow-list to limit damage from malicious RT files. The whitelist lives in the project's RT properties:
- Open Runtime settings > Services > Scripting.
- Add the absolute path
C:\Recipes\to the allowed directories. - If the path is not allow-listed,
OpenTextFilereturns error70 - Permission deniedeven though the Windows ACL permits the read.
For multi-machine deployments where the file is served from a UNC share, the path must be entered as \\Server\Share\Recipes\. The Runtime service account must also have a Kerberos or NTLM trust to that share; otherwise the error shifts from 70 to 462 - remote server not found or 5 - access denied.
Error Handling and Verification
Add structured logging to every load path so failures are observable. WinCC exposes HMIRuntime.Trace for the diagnostics window and HMIRuntime.LogWrite for the system log:
Sub LoadConfig()
Dim sVal, sPath
sPath = "C:\Recipes\Config.ini"
On Error Resume Next
sVal = ReadINIValue(sPath, "Runtime", "BatchSize", "100")
If Err.Number <> 0 Then
HMIRuntime.Trace("INI read failed: " & Err.Number & " " & Err.Description & vbCrLf)
Err.Clear
Else
SmartTags("BatchSize") = CInt(sVal)
HMIRuntime.LogWrite "Config", "HMI", 0, _
"BatchSize set to " & SmartTags("BatchSize")
End If
End Sub
Verification checklist
- Open WinCC Runtime. Confirm the diagnostics window (Start > Programs > Siemens Automation > WinCC Runtime Professional > WinCC Runtime - Diagnostics) shows the trace line.
- Open the start screen and confirm the I/O field bound to
BatchSizeshows the value from the INI, not the project default. - Temporarily rename the file to
Config.ini.bakand restart Runtime. The script should write the default value and emit a "CSV missing" or "INI read failed" trace. Confirm this behaviour because it proves the fallback path works. - Restore the file. Restart Runtime. Confirm the real value is loaded.
- Check the Windows Event Viewer under Application for any WinCC Runtime errors with source
CCAgent.
Troubleshooting Matrix
| Symptom | Most Likely Cause | Diagnostic | Fix |
|---|---|---|---|
| Tag stays at project default | Scheduler task not created or pointing at wrong function name | Open Schedulers in Runtime, check the task list | Recreate the task, recompile project, download |
File not found trace |
Working directory mismatch or UNC path typo | Add HMIRuntime.Trace oFSO.GetAbsolutePathName("...")
|
Use absolute path; verify account can read share |
Error 70 - Permission denied |
WinCC script allow-list blocks the path | RT settings > Services > Scripting | Add path to allow-list; restart Runtime |
Type mismatch on SmartTags write |
Empty INI value cast to INT | Check the INI file for blank value or missing equals | Provide default; guard with If Len(sVal)>0 Then
|
| Garbled accented characters | CSV saved as UTF-8 BOM but opened ASCII | Inspect file with Notepad++ hex view | Pass -1 to OpenTextFile (Unicode mode) or save CSV as ANSI |
| Tag flickers from default to file value | Loader runs in screen Loaded event instead of startup scheduler | Move call from screen Loaded to scheduler Runtime start | Use the scheduler; verify ordering |
| Works in Simulator, fails in RT | Simulator runs under interactive user; RT runs under service account | Compare identity with whoami in cmd |
Grant service account read on the file |
| File loaded once, never refreshed on subsequent Runtime starts | OS file cache or Runtime caching the value | Add SmartTags("BatchSize").Write after assignment |
Force commit, then re-evaluate scheduler trigger |
Comparison with Other Recipe Mechanisms
WinCC Professional also includes a native Recipes object (HMIRuntime.Recipes) that stores data in a binary .rdb file rather than plain-text CSV or INI. The native recipe object gives concurrent access, versioning, and a built-in view, but it requires the operator to actively load/save a recipe and it cannot be hand-edited outside WinCC. The CSV/INI approach documented here is appropriate when:
- An MES or ERP system must drop the file from outside the WinCC project.
- An engineer needs to edit values in Notepad or Excel.
- The startup value set is small (under a few dozen tags) and rarely changes.
For projects on Allen-Bradley PanelView Plus, the recipe import flow is fundamentally similar - browse to a .csv file via FactoryTalk View SE recipe import or PanelView Plus parameter file - but the script and tag namespaces are completely different. Likewise, AutomationDirect's C-more HMI offers a one-click Import Recipe Sheet action documented in the official C-more help system, where the operator selects a CSV from the project folder and the panel writes its values into a recipe structure automatically - no scripting required, but the import is manual and bound to a screen button rather than a startup event.
The WinCC CSV/INI approach occupies a middle ground: fully automated at Runtime start, but text-based and editor-friendly.
Field-Commissioning Notes
- Always create the recipe file before downloading the WinCC project so the script has something to read on first start.
- Wrap the loader in
On Error Resume Nextplus anErr.Clearat the end. An unhandled VBS error inside a scheduler task freezes subsequent tasks for that cycle and is hard to trace. - Pre-validate the recipe with a checksum line at the bottom (e.g.
;SHA256=...). Read it in VBS and refuse to load if the checksum fails - this catches a truncated upload. - Keep the file under 64 KB if the Runtime target is a panel with Windows Embedded Compact; larger files increase startup latency visibly.
- If the file is dropped by a Windows scheduled task, use
FileSystemObject'sGetFile.LastModified to detect changes and reload only when newer than the tag's last update time.
FAQ
Which Siemens FAQ covers loading a CSV at WinCC Professional Runtime startup?
FAQ 850338 covers file access with VBS in WinCC V7.2 and Professional using Scripting.FileSystemObject; the same code runs unmodified in TIA Portal V13 and later. For Panel/Advanced Runtime, use FAQ 106501825.
Do I need a special license to run VBScripts that read files in WinCC Professional V13?
Yes. The WinCC Professional RT option must be licensed separately from TIA Portal. The script runtime is part of that license; without it, scripts are skipped silently at startup.
Why does my CSV read succeed in the TIA Simulator but fail in the real Runtime?
The Simulator runs under your interactive Windows account, while the Runtime service runs under the SIMATIC HMI system account. Grant that account Read on the directory and add the path to the script allow-list under RT settings > Services > Scripting.
Can I write to the same CSV at Runtime stop to save current values?
Yes. Mirror the read routine with a write routine that calls oFile.WriteLine and schedule it on Runtime stop instead of Runtime start. Use OpenTextFile(sFile, 2, True, -1) - the second argument is IOMode = 2 for write, the third is True to create the file if missing.
Should I use INI or CSV for a small startup recipe?
Use CSV when the list is longer than about five entries or when it is shared with Excel/MES. Use INI when you want named sections (for example one section per machine area) and only a handful of keys per section. Both parse with the same VBS skeleton shown above.