Delphi: Where is the shortcut that started the application?

<>

This question already has an answer here:

Answers


You can do that using GetStartupInfo with the STARTF_TITLEISLINKNAME flag:

const
  STARTF_TITLEISLINKNAME = $800;

function GetShortcutName(out LinkName: string): Boolean;
var
  si: TStartupInfo;
begin
  Result := False;
  FillChar(si, SizeOf(TStartupInfo), 0);
  GetStartupInfo(si);
  if (si.dwFlags and STARTF_TITLEISLINKNAME) <> 0 then
  begin
    Result := True;
    LinkName := si.lpTitle;
  end;
end;

Test code (tested on Win7 64 with XE8 and Delphi 10 Seattle - not tested on Win8 or 10):

program GetShortCutTest;

{$APPTYPE CONSOLE}

uses
  System.SysUtils,
  Windows;

var
  sLink: string;

begin
  if GetShortcutName(sLink) then
    WriteLn('Shortcut: ' + sLink)
  else
    WriteLn('Not run from shortcut.');

  ReadLn;
end.

You can test it by running the test app (which will show 'Not run from shortcut.'), and then creating a shortcut to the test app and executing that shortcut (which then shows 'Shortcut: ' and the name of the .lnk file).


Need Your Help

Is it Possible to make a button as File upload Button?

javascript php jquery forms file-upload

I am new in php. I have a form on which i place a button Value as Upload MB when user click on this button it redirects on a web form where i place a file upload control and user upload file here. ...

Implement swipe action from specific portion of Screen using "ECSlidingViewController"

ios ecslidingviewcontroller

I have ECSlidingViewController working perfectly but I want to implement it in such a way that when the user tries to swipe action is not carried out when the user tries to swipe from the header se...