Bubble tip fails when deployed as login script

Welcome Forums General PowerShell Q&A Bubble tip fails when deployed as login script

This topic contains 1 reply, has 2 voices, and was last updated by

11 months ago.

  • Author
  • #97154

    Points: 0
    Rank: Member

    We are trying to notify our users that there will be a password policy being put in place by using the script below. It keeps erroring out with the error below. Below the error is the script we are trying to get working.

    Unable to find type [System.Windows.Forms.ToolTipIcon].
    At line:37 char:9
    + [System.Windows.Forms.ToolTipIcon]$MessageType="Info",
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.Windows.Forms.ToolTipIcon:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

    Function Invoke-BalloonTip {

    Param (
    [Parameter(Mandatory=$True,HelpMessage="The message text to display. Keep it short and simple.")]

    [Parameter(HelpMessage="The message title")]
    [string]$Title="Attention $env:username",

    [Parameter(HelpMessage="The message type: Info,Error,Warning,None")]

    [Parameter(HelpMessage="The path to a file to use its icon in the system tray")]

    [Parameter(HelpMessage="The number of milliseconds to display the message.")]

    Add-Type -AssemblyName System.Windows.Forms

    If (-NOT $global:balloon) {
    $global:balloon = New-Object System.Windows.Forms.NotifyIcon

    #Mouse double click on icon to dispose
    [void](Register-ObjectEvent -InputObject $balloon -EventName MouseDoubleClick -SourceIdentifier IconClicked -Action {
    #Perform cleanup actions on balloon tip
    Write-Verbose 'Disposing of balloon'
    Unregister-Event -SourceIdentifier IconClicked
    Remove-Job -Name IconClicked
    Remove-Variable -Name balloon -Scope Global

    #Need an icon for the tray
    $path = Get-Process -id $pid | Select-Object -ExpandProperty Path

    #Extract the icon from the file
    $balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($SysTrayIconPath)

    #Can only use certain TipIcons: [System.Windows.Forms.ToolTipIcon] | Get-Member -Static -Type Property
    $balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]$MessageType
    $balloon.BalloonTipText = $Message
    $balloon.BalloonTipTitle = $Title
    $balloon.Visible = $true

    #Display the tip and specify in milliseconds on how long balloon will stay visible

    Write-Verbose "Ending function"


    Invoke-BalloonTip -Message 'Your Password will Expire on Friday, April 6th. If you have reset your Password within 10 days you will not be prompted to change' -Title 'Attention!' -MessageType Info

  • #97157

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Please format your code :). Instructions are above the posting text box.

    The difficulty you often run into with logon scripts is that the user profile and system aren't yet fully loaded at that time. It can cause all kinds of weird, transient problems. Looks like you've asked at https://social.technet.microsoft.com/Forums/windowsserver/en-US/ace4411d-8244-4ee3-95ba-063a4f48b3ac/user-notification-script?forum=winserverManagement already and not had any love ;). Personally, I try to stay away from login scripts and user interaction of any kind for this reason.

    This particular problem is one I've seen before, and as near as I can tell it just comes down to the system condition at the time of login. You could try explicitly loading System.Windows.Forms to see if that helps, or just give up on setting the icon.

The topic ‘Bubble tip fails when deployed as login script’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort