PowerShell & VistaMenuAnswered

Hello! :)

Hopefully I can get some insight into for VistaMenu to work in PowerShell. Below is my full PowerShell code and I want to simply add an image to the original Context Menu. From what I can tell, this should be straight forward but when I set the image on the menuitem, no image is applied when I run and I also receive no errors indicating I have done something wrong.

Can you potentially point me in the right direction?

# Add all possible assemblies
Add-Type -AssemblyName System.Windows.Forms, System.Drawing, PresentationCore, Presentationframework, Microsoft.VisualBasic, WindowsFormsIntegration

# Import VistaMenu.dll
Add-Type -Path 'C:\VistaMenu.dll'

# System Tray App
$AppIcon = [System.Drawing.Icon]::ExtractAssociatedIcon('C:\windows\system32\WindowsPowerShell\v1.0\PowerShell.exe')
$SystrayApp = New-Object System.Windows.Forms.NotifyIcon
$SystrayApp.Icon = $AppIcon
$SystrayApp.Visible = $true

# Context Menu
$ContextMenu = New-Object System.Windows.Forms.ContextMenu
$ContextMenu.Name = 'Context Menu Example'

# Context Menu - MenuItem 1
$MenuItem1 = New-Object System.Windows.Forms.MenuItem
$MenuItem1.Text = 'Test'
$ContextMenu.MenuItems.Add($MenuItem1)

# Context Menu - MenuItem 2
$MenuItem2 = New-Object System.Windows.Forms.MenuItem
$MenuItem2.Text = 'Exit'
$ContextMenu.MenuItems.Add($MenuItem2)

# Set image on Context Menu (With VistaMenu control)
$VistaMenu = New-Object wyDay.Controls.VistaMenu
$VistaMenu.SetImage($MenuItem1, $AppIcon) # Trying icon, but already have tried image and same result

# Add Context Menu to System Tray (Right-Click)
$SystrayApp.ContextMenu = $ContextMenu

# Add Click - Context Menu - MenuItem 2
$MenuItem2.add_Click({ 

    # Ensures System tray icon is hidden before application closes
    $SystrayApp.Visible = $false; $SystrayApp.Dispose()

    # This exits the application properly 
    [System.Windows.Forms.Application]::Exit(); Stop-Process $PID -Force

})

# Appplication Context (Helps with responsivness and threading)
$AppContext = New-Object System.Windows.Forms.ApplicationContext 
[System.Windows.Forms.Application]::Run($AppContext)
Answer

Of course I get it working soon after I post for assistance…

After looking at this post: https://wyday.com/forum/t/623/vistamenu-with-a-notifyicon/

All I had to do was call the .EndInt() after everything and before the App Context run. Hopefully this helps someone else at least.

# Manual call becuase of Application Context
$VistaMenu.EndInit()