I'm running a script in PowerShell using Task-Scheduler on system start which runs a command. I want to control what happens when I click the minimize or close buttons on this PowerShell window. I would like the process to get hidden (minimized to system tray) instead of
- minimizing in the task-bar on clicking the minimize button or
- terminating the process and closing on clicking the Cross (X) button
Using the below resources, I was able to add a system tray icon in the taskbar with few menu items to show and hide the window when necessary.
Note that I was able to disable the Cross (X) button by using the below code from this link:
[Win32.NativeMethods]::EnableMenuItem($hMenu, $SC_CLOSE, $MF_DISABLED) | Out-Null
But I don't want to disable it, Instead I want it to minimize to system tray