Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
601 views
in Technique[技术] by (71.8m points)

c# - Register file extension in window registry?

I want to register my own project extension in window registry. I searched on google, at least i found this code, this works well, but I don't understand one line. What is meaning of "%L".

The C# code is

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();

that is line which confuse me,

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

Please explain, I'm very thankful to you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If your application executable is in C:your diryour program.exe the line is translated to:

"C:your diryour program.exe" "%L"

%L is translated to the file you're opening, so your program is executing having that file as the first parameter


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...