installation - 在 MSI 安装期间重新启动 Explorer.exe 不起作用

标签 installation windows-installer setup-project explorer shell-extensions

我有一个 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/

相关文章:

php - 转换 LAMP 应用程序以作为 Windows MSI 分发

windows-installer - 如果注册表中存在特定键,则中止 Install Shield 安装

c++ - C++ : . NET Framework 警告的 Visual Studio 设置

Python setuptools - 在子文件夹中维护文本文件引用?

python - 我想清理我的 pip/homebrew/python 安装

python - 在 Windows 上安装 python 的最佳方法是什么

c# - 在 Visual Studio 2013 中创建应用程序设置

python - 失败 `CDLL(/opt/local/lib/libgeos_c.dylib)` - Python; Mac OS X

xml - 根据 RegistrySearch 的结果设置目录

.net - 更改整个 Windows 窗体应用程序的当前区域性 .NET Compact Edition