从Process.Start启动时,应用程序图标为空白 [英] Application icon is blank when started from Process.Start

查看:173
本文介绍了从Process.Start启动时,应用程序图标为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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!

上面的代码对于几个项目都可以正常工作,但是对于一个特定的程序却失败了-让我们将其称为projectX.exe.我已经重写了projectX.exe的Main和启动方法,以便它们模仿另一个显示其图标很好的项目.

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.

如果我要求以管理员身份运行projectX.exe,则该图标显示正常,但该选项对我的客户端不可用.

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

编辑2017年10月20日 如果我将"projectX.exe"的名称更改为其他名称,例如"test.exe",则图标在任务栏中显示确定".程序的图标在注册表中存储在哪里?

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?

编辑2017年10月22日 按照建议刷新图标后,从文件资源管理器运行程序或创建快捷方式时,图标不再显示在任务栏中.

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.

编辑2017年11月12日 以管理员身份运行程序,该图标将按预期显示在任务栏中.

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

推荐答案

如果我将'projectX.exe'的名称更改为其他名称,那么该图标将显示OK.

If I change the name of 'projectX.exe' to something else ... then the icon shows OK.

这绝对是一个图标缓存引发的问题.尚不清楚为什么将其重置无助于解决此问题,但似乎您是手工完成的,并且有可能无法正确显示.

This is definitely an icon cache induced problem. It is not very clear why resetting it did not help to solve this problem, but it looks like you did it by hand and that has ways of not panning out correctly.

一些背景.这个问题在开发机器上很常见,程序员倾向于在调试和测试程序后才照顾chrome.资源管理器必须看到带有错误图标的program.exe文件,然后将其复制到缓存中.更改.exe不会强制其刷新缓存的副本,这可以说是一个错误.否则,高速缓存对于Explorer而言非常重要,在主轴驱动器上从文件视图中的文件图标中挖掘图标会很容易,只需几秒钟即可.

Some background. This problem is pretty common on a dev machine, programmers tend to take care of the chrome only after getting their program debugged and tested. Explorer got to see their program.exe file with the wrong icon and copied that into its cache. Changing the .exe does not force it to refresh the cached copy, arguably a bug. The cache is otherwise pretty important for Explorer, digging the icons out of the files on a folder view full of files can take any easy handful of seconds on a spindle drive.

缓存存储在文件中,而不是注册表中.您会在c:\ users \您的名字\ appdata \ local \ iconcache.db中找到它,请注意它是一个隐藏文件. Windows 8及更高版本使用带有多个icon * .db文件的更高级的缓存方案,这些文件存储在c:\ users \您的名字\ appdata \ local \ microsoft \ windows \ explorer目录中.

The cache is stored in a file, not the registry. You'll find it back in c:\users\yourname\appdata\local\iconcache.db, beware that it is a hidden file. Windows 8 and up use a much fancier caching scheme with multiple icon*.db files, stored in the c:\users\yourname\appdata\local\microsoft\windows\explorer directory.

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

Deleting these files is enough to force Explorer to re-create them. But that doesn't necessarily come a good end, you can only be 100% sure that Explorer creates a fresh copy by terminating it before you delete the files. And other processes may have a lock on these files if they have the cache file open while you are doing this, typically because they have a shell extension loaded.

我认为重置缓存的最佳方法是使用Ramesh Srinivasan的cleariconcache.vbs脚本,该脚本可从

I think the best way to reset the cache is by using Ramesh Srinivasan's cleariconcache.vbs script, available from this web page. His VBScript code looks convincingly right, taking care of all the corner-cases and dutifully reporting failure. Close all running programs to give it maximum odds for success.

这篇关于从Process.Start启动时,应用程序图标为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆