IMDTouchKnowledge BaseShop main store

Troubleshooting

Why WinCC Unified Scripts Cannot Launch a Batch File

HMI and touchscreens Published 6 min read

Short answer

The WinCC Unified runtime's JavaScript API has no documented function that starts an external program, so SystemFunctions.launch fails on every path, escaping and wrapper you try. Do the PDF select, rename and copy with the runtime's Node.js fs module, or trigger a host-side service from a tag and keep execution outside the HMI.

On this page
  1. Why does SystemFunctions.launch fail in WinCC Unified?
  2. Is there any Unified script function that starts an external program?
  3. Where does a WinCC Unified script actually execute?
  4. How do you pass the motifPDF value instead of the tag object?
  5. How do backslashes work in the path string?
  6. How do you rename and copy the PDF without a batch file?
  7. How do you run the batch file when the runtime cannot launch it?
  8. How do you tell a script error from a file-permission error?
  9. Questions asked

A button script in a WinCC Unified runtime calls SystemFunctions.launch on a .bat file and nothing starts, no matter how the path is written. The reason sits above the path: the Unified runtime's JavaScript interface has no documented function that starts an external process, so the call fails at method resolution — before one or two backslashes, a hard-coded path, or a VBS launcher could matter. The workflow behind the button, selecting a PDF in C:\PDF_Ecran1, renaming it from the motifPDF tag and delivering it to \\ECRAN2\PDF_Ecran2, is still reachable two ways: the runtime's documented file access (the Node.js fs module) covers select, rename and copy in script, and anything that truly needs cmd.exe belongs in a host-side service the script triggers.

Why does SystemFunctions.launch fail in WinCC Unified? #

Because the method is not part of the runtime's scripting interface: WinCC Unified scripts run as JavaScript against a documented object model that lists no launch function for external programs, so the call fails at method resolution before any path string is evaluated.

That failure is independent of everything you varied. One backslash or two, the path hard-coded into the call, a .vbs launcher instead of the .bat — every variant still needs something to start it, and no documented starter exists in the script interface of the runtime.

JavaScript identifiers are case-sensitive, and a name that resembles a function from another HMI generation is not evidence it exists here; only the scripting documentation for the installed Unified version decides. If the name is a habit carried over from WinCC flexible or WinCC Professional, those are different products with different object models — the differences between WinCC Explorer, Advanced, Professional, Flexible and Unified are exactly the line you crossed.

Is there any Unified script function that starts an external program? #

None is documented: the runtime scripting reference for Unified lists file access through the Node.js fs module and web access for internet content, and no general process-launch function appears anywhere in that list.

That also answers the question behind the button — "Unified script cannot do my file gymnastics" is half wrong. It cannot start a process; it can select, rename and copy files on the runtime host through fs, which is the whole job the batch file was doing. Split the decision by what the job needs:

  • File movement only — pick the PDF, rename it, copy it to the share: do it in script with fs, with no batch file at all.
  • A command interpreter or an .exe — anything cmd.exe-specific: take it out of the HMI and run it host-side.

Verify the capability set against the documentation for the exact version installed; the same discipline shows up elsewhere, since Unified script has no native .xlsx creation and the documented export route is CSV from logged data.

Where does a WinCC Unified script actually execute? #

On the runtime host: the script runs inside the Unified runtime that serves the screens, so C:\PDF_Ecran1 and \\ECRAN2\PDF_Ecran2 resolve on that machine, under its service identity — not on the browser client displaying the page.

A browser showing the visualization is a display surface, not an execution engine, and the engineering station is neither, unless it hosts the runtime. Establish which machine that is before touching any path: the options for where WinCC Unified runtime can run fix where the PDF folder and the share must be reachable.

How do you pass the motifPDF value instead of the tag object? #

Read the value, not the reference: in the failing pattern, let OF = Tags("motifPDF"); stores a tag object and hands that object to the launch call, so the argument is wrong even before the launch question is settled.

Obtaining a tag reference and reading its current value are two separate operations. Read the value through the documented read operation, log it with its type, and reject an empty or non-matching selection before any file is touched. Treat the value as data from outside your code: if it becomes part of a filename or a command line, spaces, quotes and command-interpreter metacharacters change how the result parses, so validate it against the filename format you permit.

How do backslashes work in the path string? #

Write each backslash twice in the literal: the source text "C:\\PDF_Ecran1\\move_pdf_byname.bat" evaluates to C:\PDF_Ecran1\move_pdf_byname.bat, and a UNC value keeps its two leading backslashes, so its literal is "\\\\ECRAN2\\PDF_Ecran2".

Counting them turns it into arithmetic. The local-path literal holds 4 backslashes and evaluates to 2: one before PDF_Ecran1, one before the filename. The UNC literal holds 6 and evaluates to 3: two leading, one before PDF_Ecran2. With single backslashes, as in "C:\PDF_Ecran1\launch_script.vbs", each one is consumed as an escape character and the evaluated path loses them. Escaping fixes string construction only; it never adds a method to the API, which is why one-versus-two changed nothing about the launch error.

How do you rename and copy the PDF without a batch file? #

Entirely in script, through the documented file interface: read the motifPDF value, pick the matching PDF in C:\PDF_Ecran1 on the runtime host, rename it, then copy it to \\ECRAN2\PDF_Ecran2 — every step the Node.js fs module covers.

Prove it in stages with a disposable PDF, recording the result at each boundary:

  1. Handler: one button press produces one diagnostic entry, with no exception before the file operation.
  2. Selection: the logged motifPDF value and its type match the test document's rule.
  3. Source: the PDF exists and opens under the identity the runtime runs as, on the runtime host.
  4. Local rename: the renamed file exists and opens; a conflicting name follows the reject, replace or versioning rule you chose.
  5. Network copy: the destination exists in \\ECRAN2\PDF_Ecran2 with the expected name and size, and opens.

Three field realities survive the redesign. A PDF can appear in the folder before its producer finishes writing, so trigger on a completion indication rather than on file presence, or locked-file errors will come and go. Repeated presses start overlapping operations on the same document, so track active and completed states. And decide explicitly whether the source file remains after the transfer.

How do you run the batch file when the runtime cannot launch it? #

From outside the HMI: keep the .bat on the runtime host and start it with a Windows mechanism — a service or scheduled task watching a trigger the script controls, such as a tag value or a handoff file the script writes.

The script's part shrinks to writing the trigger: the filename built from motifPDF, placed in a tag or a handoff file. The watcher executes under a Windows account you choose, which settles share access cleanly and keeps the permission grant limited to this one workflow. That is the standing decision: file movement lives in the script with fs; anything needing a command interpreter lives host-side and is triggered, never launched from the screen.

How do you tell a script error from a file-permission error? #

By where it stops: a method-resolution or type error surfaces in the runtime's script diagnostics before anything executes, while access-denied or path-not-found shows up only after a call runs and the host touches the file or share.

Map the observation to the fault:

  • Script exception on the button press — event binding, method availability, argument types.
  • Script completes and nothing starts — no launch interface exists in this runtime, which is the case here; no wrapper fixes it.
  • The external step runs but selects no PDF — tag value or filename matching.
  • Local rename works and the network copy fails — the executing identity against share and folder permissions.

Capture the exact runtime error text before editing the script again: the first class calls for a redesign, the second for a permission fix, and they take opposite corrections.

Questions asked

Does wrapping the batch file in a VBS launcher help?

No. The runtime would still have to start one external process, and no documented Unified script function does that, so the wrapper only changes which file fails to start, while adding a second script to maintain. Solve execution by moving it outside the runtime, not by rewrapping the file you cannot launch.

Can the script copy the PDF straight to the network share?

Yes, as a plain file operation the fs module can address a UNC destination, but the path resolves on the runtime host under the identity the runtime service runs as, not the operator logged at the screen. Grant that identity the share and folder permissions, then prove it with a copy run from the host before suspecting the script.

Why did this approach work in my older WinCC projects?

Earlier WinCC generations scripted in a different language against a different object model, so a method that existed there says nothing about Unified. Runtime scripts here are JavaScript, and only what the documentation for your installed version lists exists at runtime. Judge capability against that list, never against memory of another product.

Where can I see everything a Unified runtime script is allowed to call?

In the script editor, right-click inside the editor to open the menu and drill into the HMI Runtime and Logic snippet groups; that list reflects the interface the installed version exposes. If a function appears nowhere there and nowhere in the documentation, it does not exist at runtime, whatever a copied snippet suggests.

Keep reading

  • Troubleshooting

    Why WinCC Unified simulation will not open in a browser

    Browse to the engineering PC's host name followed by /WebRH, because WinCC Unified simulation runs on that PC and not at the configured device IP. If the page still will not load, confirm the project runs in Runtime Manager, then check the WinCC Unified certificate in IIS. If the page opens and login fails, download again with 'keep user administration data' unchecked.

    HMI and touchscreens

  • Troubleshooting

    Why WinCC Flexible Cannot Connect to a TP177 Micro by USB

    The tag exchange with the S7-200 only proves the panel's runtime path; a project download uses a separate PC-to-loader path through the USB/PPI Multi-Master cable. With the transfer channel enabled and USB selected, the gate is the cable's E-Stand revision: an E-Stand:02 cable never reaches the TP177 Micro loader, and E-Stand:05 or later does.

    HMI and touchscreens

  • Troubleshooting

    Why a WinCC connection alarm cannot hand its text to a script

    WinCC Advanced V13 has no documented VBScript interface that hands the resolved text of system event 220006 to a script, and that event reports a restored connection, not a lost one. GMsgFunction, the Horn tag and the AlgView database belong to other editions. Keep system events for the operator, identify the failed Modbus RTU slave from per-device status tags, and trigger the script from those.

    HMI and touchscreens