VBscript to add program to notification area?


  1. Posts : 1
    Windows 7 64 Enterprise
       #1

    VBscript to add program to notification area?


    I'm creating an image which must build in an unattended fashion. The client (the end user of the resulting image) wants to have the icon for one of the included programs included in the notification area. While this CAN be done manually, because of the required build process, I do not have the option of manually adding the program to the notification area; I will need to automate this via a script or other method.

    I've found VB scripts for adding ("pinning") programs to the Start Menu and Taskbar, but not for the Notification Area.

    EDIT: To clarify further, I want to change the Behavior for this program from "Only show notifications" to "Show icon and notifications", but do so from a command line or script.

    Can anyone point me in the right direction to getting this automated?

    TIA!
      My Computer


  2. Posts : 934
    Windows 8.1 ; Windows 7 x86 (Dec2008-Jan2013)
       #2

    That is a very challenging task.

    Those things are kept decoded and in binary format.
    HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify
    "PastIconsStream" = stores the icons data
    "IconStreams" = stores the program path, caption and tip

    So, technically, if they are coded the same way across all computers, and you would know how your program adds and codes itself there, during installation you could dump both values from user's computer, then add your data and write new complex strings (old+yours) back in the registry.


    Or you could try something like Autoit script to do it semi-manually (but user will see what is going on).

    Or you could force them all to Show icon and notification (Option two here), but that would not be fair to the end user.


    I do not see an easy elegant solution here.
      My Computer


  3. Posts : 4
    Windows7
       #3

    I have solved this issue finally. I spent 6 hours looking for this answer today .... i'll post the full solution tomorrow as its time to head home now.
      My Computer


  4. Posts : 4
    Windows7
       #4

    So here's my solution ....

    2 files are required for this. A .bat file and a .ps1 file.

    Take the powershell code from this website, which i DID NOT write, so i wont take credit for (read the whole page, it explains it in full detail) and paste that code in the .ps1 file. Thats all you need to do with this file.

    Windows 7 Notification Area Automation – Falling Back Down the Binary Registry Rabbit Hole « Xtreme Deployment

    The second file is a .bat file, where you'll put the commands to run the .ps1 file. The powershell script takes 2 inputs, the first is the name of the notification icon you want to make the change to, and the second is which of the three available options you want to set.


    • 0 = only show notifications
    • 1 = hide icon and notifications
    • 2 = show icon and notifications


    For my specific application of this solution, I wanted to set the Zenworks Notification Icon to level 2 so its always in the notification area for users to click on since there is a lot of easy to access information available from there. IP address, system name ... things they need to get support from our helpdesk.

    so my .bat file looks like this:

    taskkill /im explorer.exe /f
    powershell Set-ExecutionPolicy Unrestricted
    powershell .\ZNIexeEdit.ps1 ZenNotifyIcon.exe 2
    powershell Set-ExecutionPolicy Restricted
    explorer.exe

    you kill windows explorer, which is necessary for the script to change the registry entry that controls the notification icons

    HKCU\Software\Classes\Local Settings\Microsoft\Windows\CurrentVersion\TrayNotify\IconStreams

    then you have to set the rights level of powershell

    then you call your script with your 2 parameters

    then you set the rights level of powershell back to its original state cuz you dont wanna leave it unrestricted

    then you restart explorer

    all done. both the .bat and the .ps1 need to be in the same directory, i used them right out of C:\ and you just need to launch the .bat file. so you have 2 small files that are easy to distribute through whatever means.

    it is important that the actual user of the machine be logged in at the time the .bat file is executed.
      My Computer


  5. Posts : 1
    Windows 7 Pro SP1 x64
       #5

    Information


    I applied the script "NotifyIcon.ps1" and "NotifyIcon.bat" by GPO but the policy does not apply to the Windows Update icon in systray.

    How did you do?

    NotifyIcon.bat
    taskkill /im explorer.exe /f
    powershell Set-ExecutionPolicy Unrestricted
    powershell .\NotifyIcon.ps1 wuauclt.exe 2
    powershell Set-ExecutionPolicy Restricted
    explorer.exe

    NotifyIcon.ps1
    param(
    [Parameter(Mandatory=$true,HelpMessage='The name of the program')][string]$ProgramName,
    [Parameter(Mandatory=$true,HelpMessage='The setting (2 = show icon and notifications 1 = hide icon and notifications, 0 = only show notifications')]
    [ValidateScript({if ($_ -lt 0 -or $_ -gt 2) { throw 'Invalid setting' } return $true})]
    [Int16]$Setting
    )

    $encText = New-Object System.Text.UTF8Encoding
    [byte[]] $bytRegKey = @()
    $strRegKey = ""
    $bytRegKey = $(Get-ItemProperty $(Get-Item 'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify').PSPath).IconStreams
    for($x=0; $x -le $bytRegKey.Count; $x++)
    {
    $tempString = [Convert]::ToString($bytRegKey[$x], 16)
    switch($tempString.Length)
    {
    0 {$strRegKey += "00"}
    1 {$strRegKey += "0" + $tempString}
    2 {$strRegKey += $tempString}
    }
    }
    [byte[]] $bytTempAppPath = @()
    $bytTempAppPath = $encText.GetBytes($ProgramName)
    [byte[]] $bytAppPath = @()
    $strAppPath = ""

    Function Rot13($byteToRot)
    {
    if($byteToRot -gt 64 -and $byteToRot -lt 91)
    {
    $bytRot = $($($byteToRot - 64 + 13) % 26 + 64)
    return $bytRot
    }
    elseif($byteToRot -gt 96 -and $byteToRot -lt 123)
    {
    $bytRot = $($($byteToRot - 96 + 13) % 26 + 96)
    return $bytRot
    }
    else
    {
    return $byteToRot
    }
    }

    for($x = 0; $x -lt $bytTempAppPath.Count * 2; $x++)
    {
    If($x % 2 -eq 0)
    {
    $curbyte = $bytTempAppPath[$([Int]($x / 2))]
    $bytAppPath += Rot13($curbyte)

    }
    Else
    {
    $bytAppPath += 0
    }
    }

    for($x=0; $x -lt $bytAppPath.Count; $x++)
    {
    $tempString = [Convert]::ToString($bytAppPath[$x], 16)
    switch($tempString.Length)
    {
    0 {$strAppPath += "00"}
    1 {$strAppPath += "0" + $tempString}
    2 {$strAppPath += $tempString}
    }
    }
    if(-not $strRegKey.Contains($strAppPath))
    {
    Write-Host Program not found. Programs are case sensitive.
    break
    }

    [byte[]] $header = @()
    $items = @{}
    for($x=0; $x -lt 20; $x++)
    {
    $header += $bytRegKey[$x]
    }

    for($x=0; $x -lt $(($bytRegKey.Count-20)/1640); $x++)
    {
    [byte[]] $item=@()
    $startingByte = 20 + ($x*1640)
    $item += $bytRegKey[$($startingByte)..$($startingByte+1639)]
    $items.Add($startingByte.ToString(), $item)
    }

    foreach($key in $items.Keys)
    {
    $item = $items[$key]
    $strItem = ""
    $tempString = ""

    for($x=0; $x -le $item.Count; $x++)
    {
    $tempString = [Convert]::ToString($item[$x], 16)
    switch($tempString.Length)
    {
    0 {$strItem += "00"}
    1 {$strItem += "0" + $tempString}
    2 {$strItem += $tempString}
    }
    }
    if($strItem.Contains($strAppPath))
    {
    Write-Host Item Found with $ProgramName in item starting with byte $key
    $bytRegKey[$([Convert]::ToInt32($key)+528)] = $setting
    Set-ItemProperty $($(Get-Item 'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify').PSPath) -name IconStreams -value $bytRegKey
    }
    }
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 18:26.
Find Us