Small helper to launch, hide, and control console applications from the Windows system tray.
NOTICE
Not intended (currently) for GUI applications, GUI applications are unsupported.
Target platform: Windows only.
Zig Version:
- Zig 0.15.2
Dependencies:
Build:
zig buildBuild and basic debugging:
zig build -Doptimize=Debug && ./zig-out/bin/ztray.exe -pm ping.exe -- 127.0.0.1 -t; $LASTEXITCODEBuild Release:
zig build-exe -Doptimize=ReleaseSafeExecutable output:
zig-out\bin\ztray.exe
ztray [options] <program> [-- <program-args>...]
<program>: path to the target executable or script to launch.- Everything after
--(if present) is passed to<program>unchanged. - If
--is omitted, all remaining positional arguments are passed to<program>, this does not include options.
-
-i, --icon <path>Path to a.icofile to use as the tray icon.(If omitted, the target executable's,
ztrays, or default Win32 application icon will be used (in that order.)) -
-t, --tooltip <text>Tooltip text for the tray icon. (If omitted, the executable name of<program>is used.) -
-m, --minimizedStart the target application hidden. -
-p, --persistentKeep the target process alive when closing
ztray. -
-h, --helpShow usage help and exit.
ztray -m ping.exe -- 127.0.0.1 -t
Runs minimized (-m) to the Windows system tray.
ztray -i C:\icons\network.ico -t "Network Monitor" ping.exe -- 127.0.0.1 -t
Applies a custom tray icon and tooltip.
NOTICE
Each instance of
ztray.exeresults in at least three processes: the target process, its console host (conhost.exe), andztray.exeitself.
- Launches
conhost.exe, which in turn starts the target process. - Hides own console window.
- Creates tray icon.
- Enables toggling target process's
conhost.execonsole window via tray icon. - Exits automatically when target process exits.
-
Left-click tray icon
-
If window was hidden:
- Show and Activate window
-
If window was shown:
- Hide window
-
-
Right-click tray icon
- Open context menu with:
- Exit: closes
ztray.exeand target, unless--persistent, in which case target is kept alive and shown.
- Exit: closes
- Open context menu with:
-
Target exits
- When target process exits,
ztrayexits, removing the tray icon.
- When target process exits,
- Working directory: the target program inherits
ztray’s current working directory. Usingztrayfrom PATH is the best option. - Process lifetime: If the target process exits,
ztrayexits automatically.