Last active
December 24, 2020 01:26
-
-
Save SQL-MisterMagoo/1b2ac83f3d8e248091cf39d751212a1e to your computer and use it in GitHub Desktop.
Show system tray icon from poweshell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-Type -AssemblyName PresentationFramework, System.Drawing, System.Windows.Forms | |
$icon = New-Object System.Windows.Forms.NotifyIcon | |
$icon.icon = New-Object System.Drawing.Icon("someicon.ico") | |
$icon.Visible = $true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Update-ViewCount { | |
# THANKS VEXX! | |
$viewcount = Get-Random -Min 10 -Max 90 | |
[System.Drawing.Bitmap]$image = [System.Drawing.Bitmap]::New(16, 16) | |
$null = $image.SetResolution(96, 96) | |
[System.Drawing.Graphics]$surface = [System.Drawing.Graphics]::FromImage($image) | |
$color = [System.Drawing.Color]::White | |
$brush = [System.Drawing.SolidBrush]::New($color) | |
if ([int]$viewcount -gt 99) { | |
$weight = "Regular" | |
$fontsize = 8.5 | |
} else { | |
$fontsize = 12 | |
$weight = "Bold" | |
} | |
$font = [System.Drawing.Font]::New("Segoe UI", $fontsize, $weight, "Pixel") | |
$surface.DrawString($viewcount, $font, $brush, 0, 0) | |
$surface.Flush() | |
[System.Drawing.Icon]::FromHandle($image.GetHicon()) | |
} | |
Add-Type -AssemblyName PresentationFramework, System.Drawing, System.Windows.Forms | |
$icon = New-Object System.Windows.Forms.NotifyIcon | |
$icon.icon = Update-ViewCount | |
$icon.Visible = $true | |
$icon.add_Click( { | |
if ($_.Button -eq [Windows.Forms.MouseButtons]::Right) { | |
$icon.Dispose() | |
} | |
} | |
) | |
$count = 1 | |
do { | |
$icon.icon = Update-ViewCount | |
$count++ | |
Start-Sleep -Seconds 3 | |
} While ($count -le 5 -and $icon.icon) | |
$icon.Dispose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment