Windows 10 Program to either Untray or Run


Senior Member
When pinning a program to the taskbar, when you launch it it runs the actual executable then the application either runs for the first time, or if it's already running but minimized to the tray, it has to handle that 2nd exe instance -> terminate the second one -> un-minimize the currently running one.

What I've always wanted is a simple script that works as such:
if(program.exe is running and has active window)
    switch to active window (or bring it to the front)
if(program.exe is running && minimized in tray)
    untray application and bring to front
else (program is not running)
    launch executable // which is default behavior for pinned things in task-bar
This behavior in most cases already happens, but it's inefficient because the running program has to deal with the second instance and there's usually a delay for some reason.
I don't know the windows API but how hard does this sound to create?