clear icon cache in win 7 programmatically - execu

2019-04-13 00:08发布

We changed the logo-icon of our WPF application, and then the icon of the main executable. On my PC with Win 7, there is a problem with the refresh of the icon cache: the desktop shortcut to the main executable, and the preview of the icon of the executable, in Windows Explorer still shows the old icon. Even restarting the system the problem persists.

I found that running this command solves the problem:

ie4uinit.exe-ClearIconCache

My problem is that I can't run it from code. I made two attempts.


First:

Dim si As New ProcessStartInfo()
si.CreateNoWindow = False
si.UseShellExecute = False
si.FileName = "ie4uinit.exe"
si.WindowStyle = ProcessWindowStyle.Hidden
si.Arguments = "-ClearIconCache"
Dim p As Process = Process.Start(si)

error: "Could not find the specified file" - I tried to input the full path but it still doesn't find the file


Second:

I put the command in a batch file

Dim si As New ProcessStartInfo("C:\test.bat")
si.UseShellExecute = False
si.RedirectStandardError = True
si.RedirectStandardInput = True
si.RedirectStandardOutput = True
si.CreateNoWindow = True
si.ErrorDialog = False
si.WindowStyle = ProcessWindowStyle.Hidden
Dim p As Process = Process.Start(si)

This time I get no errors, but not even the desired effect. If I double-click on the batch file instead, everything is working fine.

I'd like to adjust one of these procedure otherwise finding a new one to clear the windows icon cache. C# or Visual Basic is not important... Pileggi

5条回答
我想做一个坏孩纸
2楼-- · 2019-04-13 00:52
Enables or disables file system redirection for the calling thread.


[DllImport("Kernel32.dll")]
private static extern bool Wow64EnableWow64FsRedirection(bool Wow64FsEnableRedirection);  

//.....
Wow64EnableWow64FsRedirection(false);
Dim p As Process = Process.Start(si)
Wow64EnableWow64FsRedirection(true);
查看更多
Emotional °昔
3楼-- · 2019-04-13 00:55

maybe it doesn't search for it in the path try using: as the path "%WINDIR%\System32\ie4uinit.exe", if this doesnt work try "C:\Windows\System32\ie4uinit.exe"

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-04-13 01:02

You can try this:

Dim objProcess As System.Diagnostics.Process
objProcess = New System.Diagnostics.Process()
objProcess.StartInfo.FileName = "ie4uinit.exe"
objProcess.StartInfo.Arguments = "-ClearIconCache"
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
objProcess.Start()
objProcess.WaitForExit()
objProcess.Close()
查看更多
欢心
5楼-- · 2019-04-13 01:05

I had a similar issue, trying to call ie4uinit from an Inno installer. The PATH did include the right system directories; however, doing a "dir" did not show that the file exists. In fact, there were over 100 *.exe files that could not be found from whatever shell was executing the command. Opening Explorer or a command window reveals the file is there (which of course we know). I think it is a permissions or access issue. I didn't have the patience to trace it further, but just copied ie4uinit.exe to a local directory and had my installer execute it there.

查看更多
男人必须洒脱
6楼-- · 2019-04-13 01:06

I found the solution: I had to build the executable that runs the batch file for "Any CPU", otherwise it has not sufficient permissions to run ie4unit.

Before I was trying building for "x86" and I was running the process on a Win7 64 bit...

查看更多
登录 后发表回答