55[CmdletBinding (SupportsShouldProcess = $true )]
66
77param (
8- [Parameter (Mandatory = $true , HelpMessage = ' The name of the program' )][string ]$ProgramName ,
9- [Parameter (Mandatory = $true , HelpMessage =
10- ' The setting (2 = show icon and notifications 1 = hide icon and notifications, 0 = only show notifications' )]
11- [ValidateScript ( { if ($_ -lt 0 -or $_ -gt 2 ) { throw ' Invalid setting' } return $true })]
12- [Int16 ]$Setting
8+ [Parameter (
9+ Mandatory = $true ,
10+ HelpMessage = ' Path of program' )]
11+ [string ] $ProgramPath ,
12+ [Parameter (
13+ HelpMessage = ' 0=only show notifications, 1=hide, 2=show icon and notifications' )]
14+ [ValidateScript ( { if ($_ -lt 0 -or $_ -gt 2 ) { throw ' Invalid setting' } return $true })]
15+ [Int16 ] $Setting = 2
1316)
1417
1518Begin
1619{
17- function Rot13 ($byteToRot )
20+ $script :TrayKey = ' HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify'
21+
22+ function GetStreamData
1823 {
19- if ($byteToRot -gt 64 -and $byteToRot -lt 91 )
20- {
21- $bytRot = $ ($ ($byteToRot - 64 + 13 ) % 26 + 64 )
22- return $bytRot
23- }
24- elseif ($byteToRot -gt 96 -and $byteToRot -lt 123 )
25- {
26- $bytRot = $ ($ ($byteToRot - 96 + 13 ) % 26 + 96 )
27- return $bytRot
28- }
29- else
30- {
31- return $byteToRot
32- }
33- }
34- }
35- Process
36- {
37- $encText = New-Object System.Text.UTF8Encoding
38- [byte []] $bytRegKey = @ ()
39- $strRegKey = " "
24+ param ([byte []] $streams )
25+ $builder = New-Object System.Text.StringBuilder
26+
27+ # this line will ROT13 the data so you view/debug the ASCII contents of the stream
28+ # $streams | % { if ($_ -ge 32 -and $_ -le 125) { [void]$builder.Append( [char](Rot13 $_) ) } };
4029
41- $0 = ' HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify'
42- $bytRegKey = $ (Get-ItemProperty $ (Get-Item $0 ).PSPath).IconStreams
30+ $streams | % { [void ]$builder.Append ( (' {0:x2}' -f $_ ) ) }
31+ return $builder.ToString ()
32+ }
4333
44- for ( $x = 0 ; $x -le $bytRegKey .Count ; $x ++ )
34+ function EncodeProgramPath
4535 {
46- $tempString = [Convert ]::ToString($bytRegKey [$x ], 16 )
47- switch ($tempString.Length )
48- {
49- 0 { $strRegKey += " 00" }
50- 1 { $strRegKey += " 0" + $tempString }
51- 2 { $strRegKey += $tempString }
52- }
53- }
36+ param ([string ] $path )
5437
55- [byte []] $bytTempAppPath = @ ()
56- $bytTempAppPath = $encText.GetBytes ($ProgramName )
57- [byte []] $bytAppPath = @ ()
58- $strAppPath = " "
38+ $encoding = New-Object System.Text.UTF8Encoding
39+ $bytes = $encoding.GetBytes ($path )
5940
60- for ($x = 0 ; $x -lt $bytTempAppPath.Count * 2 ; $x ++ )
61- {
62- If ($x % 2 -eq 0 )
63- {
64- $curbyte = $bytTempAppPath [$ ([Int ]($x / 2 ))]
65- $bytAppPath += Rot13($curbyte )
66- }
67- Else
68- {
69- $bytAppPath += 0
70- }
41+ $builder = New-Object System.Text.StringBuilder
42+ $bytes | % { [void ]$builder.Append ( (' {0:x2}00' -f (Rot13 $_ )) ) }
43+ return $builder.ToString ()
7144 }
7245
73- for ( $x = 0 ; $x -lt $bytAppPath .Count ; $x ++ )
46+ function Rot13
7447 {
75- $tempString = [Convert ]::ToString($bytAppPath [$x ], 16 )
76- switch ($tempString.Length )
77- {
78- 0 { $strAppPath += " 00" }
79- 1 { $strAppPath += " 0" + $tempString }
80- 2 { $strAppPath += $tempString }
81- }
48+ param ([byte ] $byte )
49+
50+ if ($byte -ge 65 -and $byte -le 77 ) { return $byte + 13 } # A..M
51+ elseif ($byte -ge 78 -and $byte -le 90 ) { return $byte - 13 } # N..Z
52+ elseif ($byte -ge 97 -and $byte -le 109 ) { return $byte + 13 } # a..m
53+ elseif ($byte -ge 110 -and $byte -le 122 ) { return $byte - 13 } # n..z
54+
55+ return $byte
8256 }
57+ }
58+ Process
59+ {
60+ $streams = (Get-ItemProperty (Get-Item $TrayKey ).PSPath).IconStreams
61+
62+ $data = GetStreamData $streams
8363
84- if (-not $strRegKey.Contains ($strAppPath ))
64+ $path = EncodeProgramPath $ProgramPath
65+ # Write-Host ( $path.Split('00') | ? { $_.Length -gt 0 } | % { [char](Rot13 ([Convert]::ToByte($_, 16))) } )
66+
67+ if (-not $data.Contains ($path ))
8568 {
86- Write-Host Program not found. Programs are case sensitive.
87- break
69+ Write-Warning " $ProgramPath not found. Programs are case sensitive."
70+ return
8871 }
8972
73+ write-host ' Found!'
74+ return
75+
9076 [byte []] $header = @ ()
9177 $items = @ {}
9278 for ($x = 0 ; $x -lt 20 ; $x ++ )
9379 {
94- $header += $bytRegKey [$x ]
80+ $header += $streams [$x ]
9581 }
9682
97- for ($x = 0 ; $x -lt $ (($bytRegKey .Count - 20 ) / 1640 ); $x ++ )
83+ for ($x = 0 ; $x -lt $ (($streams .Count - 20 ) / 1640 ); $x ++ )
9884 {
9985 [byte []] $item = @ ()
10086 $startingByte = 20 + ($x * 1640 )
101- $item += $bytRegKey [$ ($startingByte ).. $ ($startingByte + 1639 )]
87+ $item += $streams [$ ($startingByte ).. $ ($startingByte + 1639 )]
10288 $items.Add ($startingByte.ToString (), $item )
10389 }
10490
@@ -119,17 +105,18 @@ Process
119105 }
120106 if ($strItem.Contains ($strAppPath ))
121107 {
122- Write-Host Item Found with $ProgramName in item starting with byte $key
123- $bytRegKey [$ ([Convert ]::ToInt32($key ) + 528 )] = $setting
108+ Write-Host Item Found with $ProgramPath in item starting with byte $key
109+ $streams [$ ([Convert ]::ToInt32($key ) + 528 )] = $setting
110+
111+ $0 = (Get-Item $TrayKey ).PSPath
124112
125113 if (! $WhatIfPreference )
126114 {
127- $0 = ' HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify'
128- Set-ItemProperty $ ($ (Get-Item $0 ).PSPath) - name IconStreams - value $bytRegKey
115+ Set-ItemProperty $0 - name IconStreams - value $streams
129116 }
130117 else
131118 {
132- Write-Host Foo
119+ Write-Host " Set-ItemProperty ' $0 ' -name IconStreams -value $streams "
133120 }
134121 }
135122 }
0 commit comments