13
FileInfo fi = new FileInfo(fileToExcecute);
Directory.SetCurrentDirectory(fi.DirectoryName);

ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.FileName = fileToExcecute;
pInfo.RedirectStandardOutput = false;
pInfo.RedirectStandardError = false;
pInfo.CreateNoWindow = false;
pInfo.UseShellExecute = true;
pInfo.WorkingDirectory = fi.DirectoryName;
if (runas)
    pInfo.Verb = "runas";
pInfo.WindowStyle = ProcessWindowStyle.Normal;

Process p = Process.Start(pInfo);

The application icon is missing from the taskbar. It's just a blank square!

The above code works fine for several projects however fails with one specific program - lets call it projectX.exe. I have re-written the Main as well as startup methods of projectX.exe so that they mimic another project that displays its icon fine.

I have tried for days to discover why but have failed dismally. I have tried various ideas including changing the icon, changing it at runtime, as well as toggling whether it should be displayed or not.

If I require that projectX.exe be run as administrator, the icon displays fine but that option is not available to my clients.

Edit 20 Oct 2017 If I change the name of 'projectX.exe' to something else for example 'test.exe', then the icon shows OK in the taskbar. Where are the icons for a program stored in the registry?

Edit 22nd October 2017 After refreshing the icons as suggested, when running the program from File Explorer or creating a shortcut, the icon is no longer displayed in the taskbar.

Edit 12th November 2017 Running the program 'As Administrator', the icon displays in the taskbar as expected.

4

3 回答 3

7

如果我将“projectX.exe”的名称更改为其他名称...然后图标显示确定。

绝对是图标缓存引起的问题。目前还不清楚为什么重置它无助于解决这个问题,但看起来你是手工完成的,并且有方法无法正确平移。

一些背景。这个问题在开发机器上很常见,程序员往往只有在调试和测试他们的程序后才会处理 chrome。Explorer 看到他们的 program.exe 文件带有错误的图标并将其复制到其缓存中。更改 .exe 不会强制它刷新缓存的副本,可以说是一个错误。缓存对于资源管理器来说非常重要,在充满文件的文件夹视图中从文件中挖掘图标可能需要几秒钟的时间在主轴驱动器上。

缓存存储在文件中,而不是注册表中。你会在 c:\users\yourname\appdata\local\iconcache.db 中找到它,注意它是一个隐藏文件。Windows 8 及更高版本使用更高级的缓存方案,其中包含多个 icon*.db 文件,存储在 c:\users\yourname\appdata\local\microsoft\windows\explorer 目录中。

删除这些文件足以迫使 Explorer 重新创建它们。但这并不一定是一个好的结局,您只能 100% 确定 Explorer 在删除文件之前通过终止它来创建新副本。如果在您执行此操作时打开缓存文件,其他进程可能会锁定这些文件,通常是因为它们加载了 shell 扩展。

我认为重置缓存的最佳方法是使用 Ramesh Srinivasan 的 cleariconcache.vbs 脚本,可从该网页获得。他的 VBScript 代码看起来非常正确,处理了所有极端情况并尽职尽责地报告失败。关闭所有正在运行的程序,使其获得最大成功几率。

于 2017-10-20T07:31:37.907 回答
1

如果不完全了解您的环境,这个问题很难诊断。

然而,这听起来很可能是操作系统问题,而不是您的代码问题。

一种选择可能是在重新启动 explorer.exe 时以编程方式清除图标缓存,以下代码应该这样做:

foreach (Process exe in Process.GetProcesses())
{
     if (exe.ProcessName.StartsWith("iexplore"))
         exe.Kill();
     }

     // clear icon cache
     strCmdText= "del %userprofile%\appdata\local\iconcache.db /a ";
     Process.Start("CMD.exe",strCmdText);

     Process.Start("explorer.exe");
}

希望您的图标现在应该可见。

于 2017-10-15T09:03:37.853 回答
0

我们遇到了完全相同的问题,但在我们的例子中,我们的图标太大了(以 kb 为单位)。一旦我们将它缩小到 kb,问题就解决了!

于 2018-11-15T14:36:32.120 回答