c# - 如何使 MUICache 失效?

标签 c# windows registry

我通过右键单击项目 -> 应用程序 -> 程序集信息 -> 标题修改了我的 C# 应用程序名称。

如果应用程序已经安装,则它不会更新名称,因为它正在从未刷新的 MUICache 中提取应用程序名称。

我正在尝试找到一种方法,使 MUICache 以编程方式失效,以便它适本地更新应用程序名称。

谢谢

最佳答案

您可以使用以下方法删除 MuiCache 键中包含应用程序可执行文件路径的值。

MuiCache 中删除该值后,通过 Windows Open with 浏览到您的应用程序对话框将使用更新后的标题将可执行文件的路径重新添加到 MuiCache

using Microsoft.Win32;
using System.Linq;
using System.Reflection;

const string MuiCacheKeyPath =
    @"Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache";

static void DeleteExecutablePathFromMuiCache()
{
    string exePath = Assembly.GetExecutingAssembly().Location; // (1)

    using (RegistryKey muiCacheKey = Registry.CurrentUser
        .OpenSubKey(MuiCacheKeyPath, writable: true))
    {
        if (muiCacheKey.GetValueNames().Contains(exePath))
        {
            muiCacheKey.DeleteValue(exePath);
        }
    }
}

或者,如果您想直接以编程方式更新标题,而不是 DeleteValue(exePath),请调用:

muiCacheKey.SetValue(exePath, yourNewTitle);

(1) 来自 this answer问题How can I get the application's path in a .NET console application? .

关于c# - 如何使 MUICache 失效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32569317/

相关文章:

windows - 异常导致崩溃(Qt SDK 1.2.1 - Qt4.8.1、MinGW、windows)

windows - 如何自动提交Plink "Access granted. Press Return to begin session"提示

c++ - 如何使用 RegLoadKey 函数从默认用户加载 NTUSER.DAT 文件?

installation - WIX 使用 x86 安装程序安装 x64 组件?

c# - IDX10501 : Signature validation failed. child : '[PII is hidden]' , token : '[PII is hidden]' - Azure B2C

c# - Azure - WebAPI 无法连接到 Azure DB,错误 : The system cannot find the file specified [SqlException]

c# - "System.MissingMethodException was unhandled"?

windows - 强制 Windows 批处理脚本返回代码 0

windows - InnoSetup - 为默认子项添加值?

c# - 将通用类型作为 T 传递