Skip to content

Instantly share code, notes, and snippets.

@pinuke
Last active October 9, 2022 17:54
Show Gist options
  • Save pinuke/6368e9d9fc85106ed0a573922d986744 to your computer and use it in GitHub Desktop.
Save pinuke/6368e9d9fc85106ed0a573922d986744 to your computer and use it in GitHub Desktop.
PowerShell Quick Tray - Creating a SysTray Icon
Add-Type –AssemblyName System.Windows.Forms #,PresentationFramework - We won't need this until the next project log
$appContext = New-Object System.Windows.Forms.ApplicationContext
$executable = "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe"
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon( $executable )
$QuickTray = New-Object System.Windows.Forms.NotifyIcon
$QuickTray.Icon = $icon
$QuickTray.Text = "PowerShell Quick Tray"
$QuickTray.Add_MouseDown({
if ($_.Button -eq [System.Windows.Forms.MouseButtons]::Right)
{
[System.Windows.MessageBox]::Show("Hello World!")
}
})
$QuickTray.Visible = $true
[void][System.Windows.Forms.Application]::Run($appContext)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment