Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

*.lnk

Posted on 1999-01-22
19
Medium Priority
?
509 Views
Last Modified: 2010-04-06
How to open *.lnk and cheek for a target file
name  
0
Comment
Question by:ILPowerSoft
  • 6
  • 6
  • 4
  • +2
19 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 1362886
right click it and choose properties
or do you want it in code?
Barry
0
 

Author Comment

by:ILPowerSoft
ID: 1362887
Yes, i wont it in code
0
 
LVL 17

Expert Comment

by:inthe
ID: 1362888
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:ILPowerSoft
ID: 1362889
you find it and tell my how to do it
0
 
LVL 17

Expert Comment

by:inthe
ID: 1362890
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
 
LVL 17

Expert Comment

by:inthe
ID: 1362891
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
 
LVL 20

Expert Comment

by:Madshi
ID: 1362892
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
 
LVL 20

Expert Comment

by:Madshi
ID: 1362893
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
 
LVL 17

Expert Comment

by:inthe
ID: 1362894
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1362895
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
 
LVL 5

Expert Comment

by:scrapdog
ID: 1362896
I wrote a program to do this once.  I'll try to find it.
0
 

Author Comment

by:ILPowerSoft
ID: 1362897
inthe you wond my Email so "ian@gezernet.co.il"
have a good day :-)
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1362898
Actually, now that I look at my program, it's purpose was to find the shortcut keys rather than the target. :(
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1362899
ILPowerSoft, did you look at my function? Is it what you need?
0
 

Author Comment

by:ILPowerSoft
ID: 1362900
Madshi:
pleas give my an exmp how to coll the function.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1362901
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
 

Author Comment

by:ILPowerSoft
ID: 1362902
inth
the files you send my are ok, you anser the question.
0
 
LVL 17

Accepted Solution

by:
inthe earned 80 total points
ID: 1362903
Thankyou iLPowerSoft
Good luck with your project
Regards Barry
0
 

Author Comment

by:ILPowerSoft
ID: 1362904
Good day to you see you later. :)
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month15 days, 5 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question