The AppGini Blog
A few tips and tricks to make your coding life a tiny bit better.

How I Ran VBScript on a Headless Ubuntu Server (And Why Your Legacy Code Doesn’t Have to Die)

Running VBScript on headless Ubuntu with Wine

Why You Might Need VBScript on a Headless Ubuntu Server

A while ago, I was brought in as a consultant by a mid-sized manufacturing company that had a surprisingly extensive VBScript (VBScript / Windows Script Host) codebase.

These scripts weren’t “just old junk”:

  • They automated nightly data extracts from their ERP system.
  • They validated CSVs coming from external partners.
  • They triggered some gnarly batch jobs on Windows servers.
  • And they were wired into several internal tools that people still depended on.

The company wanted to move more infrastructure to Linux, especially Ubuntu servers in the cloud, and start modernizing the stack. But there was a catch:

“We can’t break any of this legacy VBScript automation, and we can’t afford a big-bang migration.”

Sound familiar?

To buy them time and reduce risk, I set up a way to run their existing .vbs scripts on headless Ubuntu. This gave us:

  • A bridge between legacy Windows scripting and a modern Linux-based infrastructure.
  • Breathing room to refactor and replace scripts gradually.
  • Automation and testing around legacy logic before the rewrite.

This post is essentially the guide I wish I’d had on day one.


Overview: Running VBScript on Headless Ubuntu

The goals:

  1. Run .vbs scripts on Ubuntu (no GUI, SSH-only).
  2. Suppress Wine noise so scripts look and feel like normal CLI tools.
  3. Make .vbs scripts directly executable via a shebang, so you can run them by name.

We’ll use:

  • Wine: to provide cscript.exe (Windows Script Host console runner).
  • A lightweight shell wrapper: for quiet, consistent execution.
  • A shebang at the top of your VBScript files: to run them like any other script.

Step 1: Install Wine on Ubuntu

On a headless Ubuntu 24.04 server, install Wine (enabling 32-bit support first):

1
2
3
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install wine

This gives you a minimal Windows runtime, including cscript.exe, which is the console-based host for VBScript.


Step 2: Confirm VBScript Runs via Wine

Create a test script test.vbs:

WScript.Echo "Hello from VBS"

Run it through Wine’s cscript.exe:

1
wine cscript.exe //nologo test.vbs

On first run, Wine will:

  • Initialize a Wine prefix under ~/.wine.
  • Complain about X/GUI because you’re on a headless server.

Wine GUI warning on headless server

You may see several warnings like the above or even more, but as long as you get:

1
Hello from VBS

your VBScript environment is working.


Step 3: Create a Quiet Wrapper for cscript.exe

We don’t want to see Wine’s verbose diagnostics or the cscript logo every time. Let’s wrap it.

Create a small shell wrapper script:

1
2
3
4
5
6
sudo tee /usr/local/bin/vbsrun >/dev/null <<'EOF'
#!/usr/bin/env bash
WINEDEBUG=-all wine cscript.exe //nologo "$@" 2>/dev/null
EOF

sudo chmod +x /usr/local/bin/vbsrun

What this does:

  • WINEDEBUG=-all disables Wine’s internal debug spam.
  • //nologo removes the cscript.exe banner.
  • 2>/dev/null hides remaining Wine stderr noise.
  • Places vbsrun in /usr/local/bin, which is typically in your PATH.

You can now run:

1
vbsrun test.vbs

and see only:

1
Hello from VBS

If you prefer to keep real errors visible, remove 2>/dev/null and just rely on WINEDEBUG=-all.


Step 4: Add a Shebang to VBScript Files

Now the fun part: making .vbs files directly executable like normal shell or Python scripts.

Add this shebang line as the very first line of your VBScript:

#!/usr/local/bin/vbsrun
WScript.Echo "Hello from executable VBS"

Note:

  • The shebang must be at the absolute top of the file (no blank lines before it).
  • The rest is just VBScript, and cscript.exe will happily ignore the shebang as a comment-like, non-VBScript line.

Step 5: Make Your .vbs Scripts Executable

Mark the script as executable:

1
chmod +x myscript.vbs

Now, run it directly:

1
./myscript.vbs

Output:

1
Hello from executable VBS

If the script is placed in a directory that’s in your PATH (for example ~/bin or /usr/local/bin), you can run it without prefixing ./:

1
2
mv myscript.vbs ~/bin/        # assuming ~/bin is in PATH
myscript.vbs

At this point, your VBScript files behave just like any other command-line tools on Linux—only they’re powered by Wine and cscript.exe under the hood.


Putting It All Together: Commands Only

For quick reference, here are the essential commands in one place.

Install Wine

1
2
3
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install wine

Create the vbsrun Wrapper

1
2
3
4
5
6
sudo tee /usr/local/bin/vbsrun >/dev/null <<'EOF'
#!/usr/bin/env bash
WINEDEBUG=-all wine cscript.exe //nologo "$@" 2>/dev/null
EOF

sudo chmod +x /usr/local/bin/vbsrun

Example VBScript with Shebang

Create myscript.vbs:

#!/usr/local/bin/vbsrun
WScript.Echo "Hello from executable VBS"

Make it executable and run it:

1
2
chmod +x myscript.vbs
./myscript.vbs

(Optional) Put it in your PATH:

1
2
mv myscript.vbs ~/bin/
myscript.vbs

Why This Matters for Legacy Code Modernization

Back to the consulting story.

This company had:

  • Dozens of VBScript files doing critical yet fragile work.
  • No test harnesses, no CI integration, and no clear migration plan.
  • A mandate to “move to Linux” plus a strong fear of breaking production.

By using the approach above on a headless Ubuntu CI runner:

  1. We ran the original .vbs scripts on Linux, unchanged.
  2. We wrapped them with a shebang so Jenkins/GitLab runners could call them like any other script.
  3. We wrote new tests around the current behavior—essentially documenting the real, messy, edge-case logic.
  4. Then, step by step, we rewrote pieces in Python, using those tests to ensure behavior stayed identical.

The results:

  • Zero downtime related to the migration.
  • No surprises from hidden legacy behavior, because tests captured it.
  • A clean path to eventually retire VBScript entirely, but on the company’s schedule—not under fire.

This is the core of what I do as a consultant:

  • Stabilize legacy automation on modern platforms (Linux, containers, cloud).
  • Build safety nets (tests, wrappers, reproducible builds) around old code.
  • Gradually replace fragile scripts with maintainable, modern implementations—without disrupting the business.

If your team is:

  • Stuck with VBScript, classic ASP, old batch files, or a patchwork of Windows-only job scripts.
  • Looking to move to Linux or the cloud without rewriting everything in one painful sprint.
  • Unsure how to introduce tests and observability around that legacy automation.

I can help design a migration that:

  • Keeps your operations running.
  • Reduces risk instead of increasing it.
  • Delivers incremental value—so you see progress long before the last legacy script is gone.

Feel free to reach out if you’d like to:

  • Audit your existing VBScript / legacy automation.
  • Set up a Linux-based or containerized execution environment like the one above.
  • Plan a phased modernization roadmap that your ops and business stakeholders can actually sign off on.

Legacy code doesn’t have to be a liability—it can be a controlled, testable bridge to a cleaner system. Running VBScript on headless Ubuntu is just one surprisingly effective tool to get there.