Solved

*.lnk

Posted on 1999-01-22
19
492 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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 20 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now