Shortcuts and their paths

How to get target path of a shortcut in Start menu, on Desktop, etc.? How to process next shortcut after checking path of previous shortcut?
And how to write paths in Memo?
Delphi 3
Step by step, please
pipigrilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
Hi pipigril,

you asked actually three questions. This is not fair and against the rules at E-E. Only one question at a time.

1) For the task of getting the path from a shortcut:

function FileNameFromLink(const LinkName: String): String;

// dereferences the given link name to the file/folder name associated with the link

var
  AObject: IUnknown;
  ASLink: IShellLink;
  APFile: IPersistFile;
  WFileName: WideString;
  PFD: TWin32FindData;

begin
  // create a helper interface to dereference the link (because this is local it will
  // be freed automatically on exit)
  AObject := CreateComObject(CLSID_ShellLink);
  ASLink := AObject as IShellLink;
  APFile := AObject as IPersistFile;
  // convert to wide string
  WFileName := LinkName;
  APFile.Load(PWideChar(WFileName), 0);
  SetLength(Result, MAX_PATH);
  ASLink.GetPath(PChar(Result), MAX_PATH, PFD, 0);
end;


2) For enumerating shortcuts just use FindFirst/FindNext as with any other file.

3) Adding the path to a memo is the easiest part:

  Mmeo1.Lines.Add(NewPath);

Ciao, Mike
0
pipigrilAuthor Commented:
But.... How to use FindNext etc.? I am beginner :-).
0
LischkeCommented:
procedure EnumerateFiles(const Folder: String; EnumProc: TGetStrProc);

var
  SR: TSearchRec;

begin
  if FindFirst(Folder + '*.lnk', faReadOnly or faHidden, SR) = 0 then
  begin
    repeat
      EnumProc(Folder + SR.Name);
    until FindNext(SR) <> 0;
    FindClose(SR);
  end;
end;

procedure TMainForm.Enum(const S: String);

begin
  Memo1.Lines.Add(S);
end;

procedure TMainForm.Button2Click(Sender: TObject);

begin
  EnumerateFiles('C:\WINNT4\Profiles\All Users\Startmenü\Programme\Microsoft Visual Studio 6.0\Microsoft Visual Studio 6.0 Tools\', Enum);
end;


Ciao, Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

rwilson032697Commented:
listening
0
yk030299Commented:
listen
0
MadshiCommented:
Mike, just one addition: In your "FileNameFromLink" function you should add this line at the end of the function:

result := pchar(result);

This will cause Delphi to cut the string at the first #0 character. If you leave it the way it is right now, the result string will always have a length of MAX_PATH. That's quite ugly...

Regards, Madshi.
0
LischkeCommented:
Good point Madshi. Thank you :-)

Ciao, Mike
0
pipigrilAuthor Commented:
Hmmm....... good. Can somebody write a small sample to me? (I don't know how to complet your code-parts. There are many ways...)
0
LischkeCommented:
There's already code for complete enumeration. What do you want more? See my comment from Wednesday, February 02 2000 - 08:26AM PST. All you need now is to create a form place a button and a memo on it, place the EnumerateFiles call in the click handler (give it a path you actually have on your machine). Copy the other code I gave you there you go..

Ciao, Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.