0

I want to create a tray-icon object, set an image for it and pin into the system tray. I have just found how to make a tray icon like a popup balloon in powershell.

But I want something like in the following photo:

The icon should be always visible and I should be able to change the image based on some events. Exactly how dropbox changes the icon when a new file is being uploaded.

Mihai238
  • 1,087
  • 13
  • 26
  • So you already know how to pin an application (like http://stackoverflow.com/questions/9739772/how-to-pin-to-taskbar-using-powershell) and you ask to change the icon shown? – Lars Truijens Mar 03 '14 at 19:34
  • 1
    No, I don't want to pin to taskbar. I want to pin the icon in system tray. – Mihai238 Mar 03 '14 at 19:41
  • 1
    So like http://technet.microsoft.com/en-us/library/ff730952.aspx? Then just don't call ShowBalloonTip. – Lars Truijens Mar 03 '14 at 19:57
  • @LarsTruijens that works to show a popup for a couple of seconds, but I want the icon to be always visible and to be able to change the image based on some events. Exactly how dropbox changes the icon when a new file is being uploaded. – Mihai238 Mar 03 '14 at 20:13
  • 1
    Then don't call Sleep and don't call Dispose until you are done with it. To change the icon you set the Icon property to your new icon. – Lars Truijens Mar 03 '14 at 20:26
  • 1
    You keep adding new details to your question. Maybe you should take a step back, read about NotifyIcon and figure out what you really want. Then ask a new question and paste the relevant code you already have in there. My guess is your next question is about how to do events in PowerShell :) – Lars Truijens Mar 03 '14 at 20:29
  • @LarsTruijens I have already implemented the events :). I wanted to make the question more clear. Thank you for your answer. I'll try that. – Mihai238 Mar 03 '14 at 20:33
  • It works. I thought that the icon is disposed but it's actually is hidden. Thank you! – Mihai238 Mar 03 '14 at 20:50
  • 1
    can you post the code? – user2305193 Oct 16 '17 at 17:12

1 Answers1

0

As per https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-powershell-1.0/ff730952(v=technet.10)?redirectedfrom=MSDN

The icon must be 16 pixels high by 16 pixels wide.

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon

$objNotifyIcon.Icon = "C:\Scripts\Forms\Folder.ico"
$objNotifyIcon.BalloonTipIcon = "Error" #optional
$objNotifyIcon.BalloonTipText = "A file needed to complete the operation could not be found." #optional
$objNotifyIcon.BalloonTipTitle = "File Not Found" #optional

$objNotifyIcon.Visible = $True
$objNotifyIcon.ShowBalloonTip(10000) #optional
KERR
  • 1,312
  • 18
  • 13