将托盘图标设置为始终显示

时间:2011-10-24 14:44:51

标签: c# .net winforms notifyicon trayicon

如何将NotifyIcon设置为始终在右侧托盘中可见: http://screensnapr.com/v/qKWHe2.png

因为它将其转移到非活动图标窗口: http://screensnapr.com/v/jjtuK0.png

问题是托盘图标有一个上下文菜单,可让某人进行屏幕截图。 因此,每当他们截取屏幕截图时,图片中都会出现非活动图标窗口,阻挡其背后的任何内容,如照片轰炸机。

我知道可以通过代码完成它,因为其他应用程序(例如comodo)已经完成了它而没有让我拖放图标到那里。 为了创建任务栏的快捷方式,我了解到你在这个文件夹中设置了一个快捷方式:

C:\Users\Username\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar

托盘有类似的东西吗?或者有一个选项,我可以使用代码。

5 个答案:

答案 0 :(得分:7)

不适用于代码,只是指示用户始终显示

http://blogs.msdn.com/b/oldnewthing/archive/2010/12/15/10105142.aspx

但是你可以通过修改注册表项来破解它

HKEY_Current_User\Software\Microsoft\Windows\CurrentVersion\Explorer\TrayNotify

检查this

答案 1 :(得分:7)

我在网上搜索,实际上是随机发现的。

长话短说,PowerShell(提供的脚本)和GPO的组合。

http://4sysops.com/archives/forcing-notification-area-icons-to-always-show-in-windows-7-or-windows-8/

长话故事,创建一个包含以下内容的PowerShell脚本:

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
    }
}

使用您选择的名称将其另存为ps1文件。

打开组策略管理MMC。选择所选的组策略对象,右键单击并选择“编辑”。在编辑器中,导航到用户配置> Windows设置>脚本>登录并单击“显示属性”。转到PowerShell选项卡,然后单击“查看文件”。

将您刚制作的脚本复制到刚刚打开的资源管理器窗口中,然后关闭窗口。

在登录脚本属性窗口中,添加新的PowerShell脚本,在脚本名称中输入您使用的脚本的名称(例如:NotifyIcon.ps1),然后在参数中输入程序名称(区分大小写) !)后跟设置使用:

0 =仅显示通知1 =隐藏图标和通知2 =显示图标和通知< ---您需要的那个

例如,如果您需要始终显示RealVNC服务器,请输入:

winvnc4.exe 2

作为参数

您可以通过几种不同的方式找到可执行文件的名称,例如打开“运行”对话框并键入msconfig并查看启动程序,手动导航到安装目录C:\ Program Files {your program}或者通过查看任务管理器中正在运行的进程来尝试匹配所需的程序。 10次​​中有9次会成功。

为了使其正常工作,用户必须先运行该应用程序,然后正确注销,以便explorer.exe有机会将更新的通知区域历史记录写入注册表。在后续登录时,脚本应成功在历史记录中找到该程序,并将其设置更新为始终显示。

您也可以尝试从PowerShell提示符手动运行脚本进行调试,但是在运行之前必须先杀掉explorer.exe('taskkill / f / im explorer.exe'),否则资源管理器将无法看到您的更新,并在退出时覆盖它。

我不赞成这个过程。我没有写它,我刚刚发现它。该剧本归功于Micah Rowland。 GPO流程的功劳归功于Geoff Kendal

没有足够的声誉来链接原作者,但顶部的作者除外。

答案 2 :(得分:6)

通知区域图标“始终可见”状态是用户通过任务栏属性对话框进行的选择。这是由适当的Windows团队做出的设计决策,可以根据用户的判断选择

出于这个原因,there is no programmatic interface允许您始终显示图标。甚至有no interface to ask if your icon is visible or not

在你的鞋子里,我只需设置一个热键,允许用户截取屏幕截图而不涉及图标(所有屏幕截图程序都这样做)。

如果用户在拍摄屏幕截图之前确实喜欢右键点击,他们可以随时通过上述任务栏属性更改其偏好。

答案 3 :(得分:0)

Microsoft明确表示这是对用户的决定,而不是可以通过编程方式进行的决策。是的,为实现这一目标,有很多实用程序可以解决这个问题,但是没有任何支持的方法可以实现您的目标。

答案 4 :(得分:0)

使用类似此脚本的内容来增强软件包,以便通过简单的复选框,用户可以决定是否将图标固定到通知区域(或不是),而无需跳过Microsoft选择放置的各种箍在可访问性方面似乎是一个奇妙的想法。

也许如果Microsoft在通知区域图标(如任务栏)上提供了右键单击pin / unpin选项,或者程序能够轻松提供此类功能,我们就不会进行此讨论。