Stop Mixing Up Your RDP Sessions: Auto-Label Remote Desktop Windows

Published: (December 12, 2025 at 02:57 AM EST)
4 min read
Source: Dev.to

Source: Dev.to

The Problem Every SysAdmin Knows Too Well

You have 8 Remote Desktop windows open. One is PROD-DB, one is TEST-APP, another is your local dev box. They all look identical. You need to restart a service… and you click the wrong window.

Production is down.

Sound familiar? The native Windows MSTSC client doesn’t give you visual cues. Sure, you can hover over the taskbar to see the hostname, but when you’re moving fast, mistakes happen.

The “Old School” Workaround (And Why It Sucks)

Most admins resort to:

  • Editing the remote machine’s hostname to include [PROD] or [TEST]
  • Using third‑party RDP managers like mRemoteNG or RD Tabs
  • Just being really, really careful (spoiler: doesn’t work)

But what if you could keep using the native MSTSC client and still get instant visual feedback?

Introducing: RDP Title Master

RDP Title Master is a tiny background utility that:

  • Monitors all your RDP windows in real‑time
  • Matches window titles against your custom rules (IP addresses, hostnames)
  • Overlays a color‑coded badge directly on the MSTSC toolbar

Note: I switched to macOS right after building this tool, so I don’t have a screenshot to share. If you try it out, please post a screenshot in the comments—I’d love to see it in action! 😅

Example Config (settings.json)

[
  {
    "Pattern": "prod",
    "Label": "🔥 PRODUCTION",
    "ColorHex": "#e74c3c"
  },
  {
    "Pattern": "192.168",
    "Label": "🏠 LOCAL",
    "ColorHex": "#2ecc71"
  },
  {
    "Pattern": "test",
    "Label": "🧪 TEST",
    "ColorHex": "#3498db"
  }
]

When you connect to prod-db-01.company.com, the toolbar instantly shows a red badge saying “PRODUCTION”. No more guessing.

How It Works (Technical Deep Dive)

1. Window Detection

The tool uses EnumWindows to scan all top‑level windows, looking for the RDP window class:

private static bool IsRdpWindow(IntPtr hwnd)
{
    string className = GetClassName(hwnd);
    return className == "TscShellContainerClass";
}

2. Title Matching

Once an RDP window is found, we grab its title (which usually contains the hostname or IP) and match it against the configured patterns:

string title = GetWindowTitle(hwnd);
var rule = _configs.FirstOrDefault(c =>
    title.Contains(c.Pattern, StringComparison.OrdinalIgnoreCase)
);

3. GDI+ Overlay

We create a transparent bitmap with anti‑aliased text and a rounded badge background, then apply it using UpdateLayeredWindow:

using (Graphics g = Graphics.FromImage(bmp))
{
    g.SmoothingMode = SmoothingMode.AntiAlias;
    g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

    // Draw rounded rectangle badge
    FillRoundedRectangle(g, bgBrush, badgeRect, 10);

    // Draw text on top
    g.DrawString(text, font, textBrush, x, y);
}

4. Daemon Mode

The app runs in an infinite loop (every 3 seconds), checking for new RDP windows. This means you can start it once in the morning and forget about it.

Why C# and Not Python/PowerShell?

Short answer: Performance and distribution.

  • Single .exe – No runtime dependencies. Just download and run.
  • GDI+ Quality – Native access to Windows graphics APIs for smooth rendering.
  • Size – With trimming enabled, the final binary is ~50 MB (self‑contained .NET 8).

The original prototype was in Python (still available in the repo’s legacy_python/ folder), but C# made it production‑ready.

Installation & Usage

Quick Start

  1. Download the latest release from GitHub.
  2. Edit settings.json with your server patterns.
  3. Run MstscTitleBar.exe.
  4. Open any RDP session and watch the magic happen.

Building from Source

git clone https://github.com/mlanies/mstsc_title_bar.git
cd mstsc_title_bar/MstscTitleBar
dotnet run

To create a portable executable:

dotnet publish -c Release -r win-x64 --self-contained -p:PublishSingleFile=true

Real-World Use Cases

1. Multi‑Environment Management

If you manage DEV/STAGE/PROD environments, color‑code them:

  • 🔴 Red = Production (danger zone)
  • 🟡 Yellow = Staging (proceed with caution)
  • 🟢 Green = Dev (break things freely)

2. Client Segregation

Consultants managing multiple clients can use patterns like:

{ "Pattern": "client-a", "Label": "Client A", "ColorHex": "#9b59b6" }
{ "Pattern": "client-b", "Label": "Client B", "ColorHex": "#f39c12" }

3. Datacenter Identification

Label servers by location:

{ "Pattern": "us-east", "Label": "🇺🇸 Virginia", "ColorHex": "#3498db" }
{ "Pattern": "eu-west", "Label": "🇪🇺 Ireland", "ColorHex": "#2ecc71" }

Known Limitations

  • Windowed Mode Only – Full‑screen RDP hides the toolbar (by design).
  • Windows 10/11 – Uses WinAPI calls specific to modern Windows.
  • Refresh Delay – 3‑second polling interval (configurable in code).

Want to contribute? PRs welcome!

Conclusion

If you’ve ever typed rm -rf / in the wrong terminal or restarted the wrong server, you know the value of visual cues. RDP Title Master is a simple, zero‑configuration tool that makes your daily workflow safer.

Try it out and let me know what you think in the comments!

GitHub:

Back to Blog

Related posts

Read more »

Just Keep Coding

Introduction We all have those days where we go to fix a bug that we thought was an easy change, but end up spending a chunk of the day trying to solve it. If...