I have found a way to generate the notification for the software that is developed using Visual Basic. I used two different files to achieve it, one is a .bat file and other one is the.ps1 file. In the .ps1 file, I inserted following code which I have posted below:
Code:
param(
[Parameter(Mandatory=$true,HelpMessage='insert name of program here')][string]$NameofProgram,
[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($NameofProgram)
[byte[]] $bytAppPath = @()
$strAppPath = ""
Function Rot13($byteRot)
{
if($byteRot -gt 64 -and $byteRot -lt 91)
{
$bytRot01 = $($($byteRot - 64 + 13) % 26 + 64)
return $bytRot01
}
elseif($byteRot -gt 96 -and $byteRot -lt 123)
{
$bytRot01 = $($($byteRot - 96 + 13) % 26 + 96)
return $bytRot01
}
else
{
return $byteRot
}
}
for($x = 0; $x -lt $bytTempAppPath.Count * 2; $x++)
{
If($x % 2 -eq 0)
{
$curbyte01 = $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 $NameofProgram 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
}
}
[Note that I have made this code according to my need, you can edit according to your need and computer’s built.]
Now you will have to make a .bat file which will run the .ps1 file that you have just made. Now the software will have various forms, that is when notification will be shown, when not and so on. I have designed three types of conditions for it. Here they are:
0 = should only show the notifications
1 = no notification and icon must be shown
2 = icon as well as notification must be shown
You can now set the icon for the software and notification in the quick launch area. You will have to deal with the IP address and system name by yourself. To play with the bat file and the ps1 file to generate the notification, you will also have to involve the explorer.exe to get things done. Now that we know what we have to do, here is how you will make the .bat file. This is how the .bat file I made looks like:
Code:
taskkill /im explorer.exe /f
powershell Set-ExecutionPolicy Unrestricted
powershell .\ZNIexeEdit.ps1 ZenNotifyIcon.exe 2
powershell Set-ExecutionPolicy Restricted
explorer.exe
This will launch the code for .ps1 file that I have given and you can then pass any two parameter that I have suggested. This is the only way that I have found which is possible to achieve the notification. You will need to place the .bat file and the ps1 file in the same folder to make them work properly.
Bookmarks