*.lnk

How to open *.lnk and cheek for a target file
name  
ILPowerSoftAsked:
Who is Participating?
 
intheConnect With a Mentor Commented:
Thankyou iLPowerSoft
Good luck with your project
Regards Barry
0
 
intheCommented:
right click it and choose properties
or do you want it in code?
Barry
0
 
ILPowerSoftAuthor Commented:
Yes, i wont it in code
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
intheCommented:
OK,
im not sure how to implement it but you need
to use  IShellLink Resolve.if you look up  IShellLink::Resolve
im win32 help you may know what to do ,im going to try and find a way to use it.
Regards Barry
0
 
ILPowerSoftAuthor Commented:
you find it and tell my how to do it
0
 
intheCommented:
would you be interested in a component that can do all this for you because i just found one.the example that came with it can open and read *.lnk files and tell you everything about it.like you can change the info and stuff.
let me know
Regards Barry
0
 
intheCommented:
ive also just recieved some stuff from ken white author of clipper functions for delphi,he has sent a unit to install (delphi 3,4)and a project which again gives you info about *.lnk files .
let me know and i'll mail it all to you.
b.t.w your questions are always the most unusual and hard i suppose that makes for good learning for us eh :-)
0
 
MadshiCommented:
Hi ILPowerSoft,

here comes my LoadShellLink function. It gives you all infos that are contained in a ShellLink. Of course you can shorten the function the way you like it. Please make sure, you free the Pidl after calling the function.

uses windows, classes, shlObj, activeX, comObj, commctrl, menus;

var NeedToUninitialize : boolean = false;

function LoadShellLink(shellLinkFile: string;
                       var description, linkedObj, params: string;
                       var pidl: PItemIDList; var findData: TWin32FindData;
                       var iconPath: string; var iconIndex: integer;
                       var workingDir, hotKey: string;
                       var showCmd: integer) : boolean;
var sl  : IShellLink;
    w1  : word;
    s1  : string;
    wfd : TWin32FindData;
    i1  : integer;
begin
  NeedToUninitialize:=NeedToUninitialize or succeeded(CoInitialize(nil));
  sl:=CreateComObject(CLSID_ShellLink) as IShellLink;
  result:=(sl as IPersistFile).Load(PWideChar(wideString(ShellLinkFile)),0)=S_OK;
  if not result then exit;
  SetLength(description,MAX_PATH+1);
  if sl.GetDescription(PChar(description),MAX_PATH)=NOERROR then description:=string(PChar(description))
  else                                                           description:='';
  SetLength(s1,MAX_PATH+1);
  if sl.GetPath(PChar(s1),MAX_PATH,wfd,0)=NOERROR then begin
    linkedObj:=string(PChar(s1));
    findData :=wfd;
  end else begin
    linkedObj:='';
    ZeroMemory(@findData,sizeOf(TWin32FindData));
  end;
  SetLength(params,MAX_PATH+1);
  if sl.GetArguments(PChar(params),MAX_PATH)=NOERROR then params:=string(PChar(params))
  else                                                    params:='';
  if sl.GetIDList(pidl)<>NOERROR then pidl:=nil;
  SetLength(s1,MAX_PATH+1);
  if sl.GetIconLocation(pchar(s1),MAX_PATH,i1)=NOERROR then begin
    iconPath :=string(pchar(s1));
    iconIndex:=i1;
  end else begin
    iconPath :='';
    iconIndex:=-1;
  end;
  SetLength(workingDir,MAX_PATH+1);
  if sl.GetWorkingDirectory(PChar(workingDir),MAX_PATH)=NOERROR then workingDir:=string(PChar(workingDir))
  else                                                               workingDir:='';
  sl.GetHotKey(w1);
  if w1 and (HOTKEYF_ALT     shl 8)<>0 then w1:=(w1 and (not (HOTKEYF_ALT     shl 8))) or scAlt;
  if w1 and (HOTKEYF_CONTROL shl 8)<>0 then w1:=(w1 and (not (HOTKEYF_CONTROL shl 8))) or scCtrl;
  if w1 and (HOTKEYF_SHIFT   shl 8)<>0 then w1:=(w1 and (not (HOTKEYF_SHIFT   shl 8))) or scShift;
  hotKey:=ShortCutToText(w1);
  if sl.GetShowCmd(showCmd)<>NOERROR then showCmd:=-1;
end;

procedure FreePidl(var pidl: PItemIDList);
var malloc : IMalloc;
begin
  if (pidl<>nil) and (SHGetMalloc(malloc)=NOERROR) then begin
    malloc.Free(pidl);
    pidl:=nil;
  end;
end;

initialization
finalization
  if NeedToUninitialize then CoUninitialize;
end.

Regards, Madshi.
0
 
MadshiCommented:
P.S: You'll find the target file is the "linkedObj" string. However, there are some links, that are not part of the normal filesystem (such as a link to a printer). In such cases you have to use the Pidl.
0
 
intheCommented:
As always thanks for input madshi
the stuff from ken is quite long and takes me about a week to sort it to a quick function. :-)

0
 
viktornetCommented:
YOu might be able to do it with ShellExecute()... I have not tried it but it might work... For checking whether the real file is there, you should use what Madshi posted...
0
 
scrapdogCommented:
I wrote a program to do this once.  I'll try to find it.
0
 
ILPowerSoftAuthor Commented:
inthe you wond my Email so "ian@gezernet.co.il"
have a good day :-)
0
 
scrapdogCommented:
Actually, now that I look at my program, it's purpose was to find the shortcut keys rather than the target. :(
0
 
MadshiCommented:
ILPowerSoft, did you look at my function? Is it what you need?
0
 
ILPowerSoftAuthor Commented:
Madshi:
pleas give my an exmp how to coll the function.
0
 
MadshiCommented:
var descr,linkedObj,params : string;
    pidl                   : PItemIDList;
    findData               : TWin32FindData;
    iconPath               : string;
    iconIndex              : integer;
    workingDir             : string;
    hotKey                 : string;
    showCmd                : integer;
begin
  if LoadShellLink('c:\windows\start menu\programs\winWord.lnk',
                   descr,linkedObj,params,
                   pidl, findData, iconPath,iconIndex,
                   workingDir, hotKey, showCmd) then begin
    // Now you have all the informations that are stored in
    // the "winWord.lnk" file in all these variables.
    // E.g. in linkedObj you will find something like "c:\office\winWord.exe"
    FreePidl(pidl);
  end;
end;

Of course you can shorten all parameters, that you don't need. I gave you the complete set of infos you can get from a shellLink file. Probably you need only some things. So if you delete the other ones, the function will be much nicer to handle...

Regards, Madshi.
0
 
ILPowerSoftAuthor Commented:
inth
the files you send my are ok, you anser the question.
0
 
ILPowerSoftAuthor Commented:
Good day to you see you later. :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.