S
S
Shadom2017-10-27 14:02:54
Programming
Shadom, 2017-10-27 14:02:54

How to pass the path to the shortcut (*.lnk) to the application?

Hello.
There is an application in C # and part of its functionality is called through the Windows context menu buttons.
Those. we work in the explorer or file manager, right-click on the file, select the action and get the result. To do this, I added to the registry a key with a "command" subsection containing a similar value:
"C:\path_to_app\App.exe" "%1"
This starts the application and passes the path to the selected file as the 1st argument (using "%1").
And everything would be fine, but if you use such a button on a *.lnk file (shortcut), then not its path is transmitted to the application, but the path to the file it points to (shortcut's target). And I need exactly the path to the shortcut, highlighting which I clicked on the button.
Are there any options with editing the "command" subsection or something else to send the application the path to the shortcut and not the file it points to?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Shadom, 2017-11-10
@Shadom

Suddenly, it will come in handy for someone:
In my case, it was important that the application was available when working in Total Commander 'e.
And I found this solution:
On the TC panel, select Start -> Edit Start Menu , then Add .
And set up a similar menu item.
where %P Inserts the original path into the command line, including the backslash (\) at the end.
and %S Puts the names of all selected files on the command line. Names containing spaces will be enclosed in quotes.
Along the way Configuration -> Settings -> Miscellaneous ->Redefine hotkeys This menu item can be assigned to a keyboard shortcut (cm_UserMenu <item number> ).
Thus, the full path to the selected file will be passed to the application.
And already in the program we use something like

string[] args = Environment.GetCommandLineArgs();

if (args.Length > 1)
{
  string filePath = args[1].ToString();
  // дальнейшие действия
}

R
res2001, 2017-10-27
@res2001

There are no options imo. This is the behavior of the Windows shell.

G
Griboks, 2017-10-27
@Griboks

At one time I used some kind of library for working with labels with codeproject.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question