views:

306

answers:

3

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.

+1  A: 

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

rossoft
you mean that %L is kind of parameter that take my opening file.
qulzam
can you know any online source which give me very brief description abt window registry.??
qulzam
exactly, that is a special keyword that is finally converted to your opening file
rossoft
Maybe the MSDN page can help you:http://msdn.microsoft.com/en-us/library/ms724946%28VS.85%29.aspx
rossoft
+1  A: 

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.

Chris Becke
A: 

%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).

Factor Mystic