我有一个 Visual Studio 安装项目,它创建一个 MSI 来安装我的应用程序。我的应用程序有一个带有图标覆盖处理程序的 shell 扩展,因此需要重新启动 explorer.exe 才能使图标覆盖处理程序开始工作。我已经注册了一个在提交时运行的自定义操作,该操作使用以下方法重新启动资源管理器:
public static void restartExplorer()
{
//stop the shell
try
{
Process process1 = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "CMD.exe";
startInfo.Arguments = "/C \"taskkill /f /im explorer.exe\"";
process1.StartInfo = startInfo;
process1.Start();
do
{
Thread.Sleep(100);
if (process1.HasExited)
{
break;
}
} while (true);
}
catch (Exception e)
{
Log.Error("restart explorer", e.StackTrace);
}
//restart the shell
string explorer = string.Format("{0}\\{1}", Environment.GetEnvironmentVariable("WINDIR"), "explorer.exe");
Process process = new Process();
process.StartInfo.FileName = explorer;
process.StartInfo.UseShellExecute = true;
process.Start();
}
当我从 Visual Studio 测试它并从命令行调用它时,此方法效果很好,但是当在安装或卸载期间从 MSI 调用它时,它会停止资源管理器,但不会重新启动它。
有谁知道为什么它可以在所有情况下工作,除了在安装或卸载期间由 MSI 调用时?
有人有其他方法可以在安装/卸载期间从 MSI 重新启动资源管理器吗?
最佳答案
老实说,我从来没有机会对此进行测试,但这里有一个快速阅读:Registering Shell Extension Handlers 。本质上:您要调用 SHChangeNotify
并指定 SHCNE_ASSOCCHANGED
事件。如果您不调用 SHChangeNotify
,则在系统重新启动之前可能无法识别更改。
在 github.com 上找到此内容: RgssDecrypter - ShellExtension.cs 。和another sample .
关于installation - 在 MSI 安装期间重新启动 Explorer.exe 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52331376/