开发者

Register file extension in window registry?

开发者 https://www.devze.com 2022-12-11 00:38 出处:网络
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\".

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.


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

"C:\your dir\your program.exe" "%L"

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


In order to understand the %L you need to understand which program is going to be doing the reading from the registry.

In this case, the verbs specified under `HKCR.ext\shell*' are read and processed by explorer.exe when it is launching programs associated with extensions.

There does not seem to be a definitive list of what explorer looks for when creating a command line. However, %L tells explorer that the program its launching will accept the long form of the filename on the command line. and long file names can have spaces in them.

Which is why programs that take long file names on the command line need to be able to handle spaces - explorer does this itself by using ',' as a command line seperator, or by allowing filenames on the command line to be enclosed in quotes.


%L is the "long name" of the file who's association has invoked your program. On modern operating systems it's identical to %1 (short name).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号