c# - 在窗口注册表中注册文件扩展名?

标签 c# windows registry

我想在窗口注册表中注册我自己的项目扩展。我在谷歌上搜索,至少我找到了这段代码,效果很好,但我不明白一行。 “%L”是什么意思。

C#代码是

string ext = ".ext";
        RegistryKey key = Registry.ClassesRoot.CreateSubKey(ext);
        MessageBox.Show(exePath);
        key.SetValue("", "My Project");
        key.Close();

        key = Registry.ClassesRoot.CreateSubKey(ext + "\\Shell\\Open\\command");
        //key = key.CreateSubKey("command");

        key.SetValue("", "\"" + Application.ExecutablePath + "\" \"%L\"");
        key.Close();

        key = Registry.ClassesRoot.CreateSubKey(ext + "\\DefaultIcon");
        key.SetValue("", Application.StartupPath + "\\icon.ico");
        key.Close();

那条线让我很困惑,

 key.SetValue("", "\"" + Application.ExecutablePath + "\" \"%L\"");

请解释一下,我非常感谢你。

最佳答案

如果您的应用程序可执行文件位于 C:\your dir\your program.exe 该行被翻译成:

"C:\你的目录\你的程序.exe""%L"

%L 被翻译成你正在打开的文件,所以你的程序正在执行时将该文件作为第一个参数

关于c# - 在窗口注册表中注册文件扩展名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1720710/

相关文章:

c# - 如何为方法创建命名 `params` 参数?

python - 为什么在 Windows 10 下启动 python 如此缓慢,以及如何加快速度

html - 电源外壳 : split HTML

installation - RegSetInfoKey 操作有什么作用?

registry - 如何启用程序集绑定(bind)日志记录?

c# - 使用 BlockingCollection<T> : OperationCanceledException, 有更好的方法吗?

c# - ParallelQuery.Aggregate 不并行运行的可能原因

c++ - 从文件导入注册表

c# - 信号量实现

c++ - 如何在 C++ 中将 double 转换为 REFERENCE_TIME?