Solved

Shell execute

Posted on 2000-04-07
23
374 Views
Last Modified: 2010-04-04
I make a short cut for a directory, but when I use ShellExecute to exec it, It can't be execute. How to open the directory shortcut?

And, the Recycle Bin, Neighbour shortcut can't exec by ShellExecute, How to open them?

Thanks
0
Comment
Question by:cookey
  • 5
  • 3
  • 3
  • +7
23 Comments
 
LVL 4

Expert Comment

by:mhervais
ID: 2695535
litening
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2695597
How did you open it?
Did you use :
ShellExecute(Handle, 'open',...

I think you must try other things than 'open' such as 'Explore'

Motaz
0
 
LVL 2

Expert Comment

by:rene100
ID: 2695851
from the sdk:
Remarks

The file specified by the lpFile parameter can be a document file or an executable file. If the file is a document file, the ShellExecute function opens or prints it, depending on the value of the lpOperation parameter. If the file is an executable file, the ShellExecute function opens it, even if lpOperation specifies printing.
Windows 95: You can use ShellExecute to open or explore a Windows 95 folder. To open a folder, use either of the following calls:

ShellExecute(handle, NULL, "path_to_folder", NULL, NULL, SW_SHOWNORMAL);

or

ShellExecute(handle, "open", "path_to_folder", NULL, NULL, SW_SHOWNORMAL);

To explore a folder, use the following call:

ShellExecute(handle, "explore", "path_to_folder", NULL, NULL, SW_SHOWNORMAL);

If lpOperation is NULL, the function opens the file specified by lpFile. If lpOperation is "open" or "explore", the function will force a open window or explorer.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2695877
What error message do you get?

Please don't forget that shellLinks do have a hidden "lnk" extension. If you use ShellExecute you have to give in the FULL path (including the ".lnk" at the end).

Regards, Madshi.
0
 
LVL 17

Expert Comment

by:inthe
ID: 2696043
i think Motaz has answered problem..
0
 

Author Comment

by:cookey
ID: 2696090
I have made a shortcut for "c:\windows\desktop" named "desk.lnk"

The following token I used

ShellExecute(0,nil,'desk.lnk',nil,nil,SW_SHOWNORMAL);

but no message shown, and no error occur
an no any more actions.

Then, I make shortcut for Recycle Bin, Neighbour, the same as directory shortcut.
0
 

Author Comment

by:cookey
ID: 2696158
OK, Thanks for everybody, I have been solved it myself, thanks very much
0
 
LVL 15

Expert Comment

by:simonet
ID: 2696181
>ShellExecute(0,nil,'desk.lnk',nil,nil,SW_SHOWNORMAL);

That will not work because the Operation parameter is missing (set to nil).

>I have been solved it myself

How did you solve it?

Alex
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2696309
The operation parameter is allowed to be set to nil (then it's the same as "open").
But I would like to know where the problem was, too.

Regards, Madshi.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 2696650
How is it going guys?
0
 
LVL 17

Expert Comment

by:inthe
ID: 2696719
hehe big hello to you viktor ;-)
been in hiding ?




0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 10

Expert Comment

by:viktornet
ID: 2696739
been busy with school and stuff... going to college soon and there are many thing on my hands at the moment... im still gonna be away for a while, but maybe once i start college ill have more time to help around here.. or maybe not.. we'll see how things go...

im happy that i got my scanner from E-E though.. great thing to have a scanner ;)
0
 
LVL 17

Expert Comment

by:inthe
ID: 2696775
alredy have a scanner so i opted for the visor.
its ok but only the "solo version" so cant be connected to pc or internet without buying extra cradle & stuff(bummer) ,well its ok for notes i suppose ,
hope to see you back here soon ;-)

Regards Barry
0
 
LVL 10

Expert Comment

by:viktornet
ID: 2696790
i hope so too, but i cant promise.. im way behind on the list ;) it's gonna take me years to get equal with you... (stop dreaming vik ;)
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2697319
Hello Viktor Ivanov.
Long time I didn't see you.
What about your study and in which year are you now?

Motaz
www.geocities.com/motaz1
0
 
LVL 15

Expert Comment

by:simonet
ID: 2698217
Yo Victor! How's everything, pal?!

Alex
0
 
LVL 10

Expert Comment

by:viktornet
ID: 2698232
IM sitll in high schooll.. ill be graduating in a month and going to UIC.. University of Illinois at Chicago.. from what i've heard it's a pretty good university..


Alex, I'm doing alright and everything's cool.. what else can i say... still learning as usually.. im into games/graphics right now... we'll see where the future would lead me to.. anyways.. ill try to have a word or two with ya everyday.. sometimes i might be abl to maeke it.. anyways.. keep up the good work guys.. talk to you later..

...-=ViKtOr=-..
0
 
LVL 15

Expert Comment

by:simonet
ID: 2698239
I hope you have not joined the dark side... er... Visual Basic!

0
 
LVL 10

Expert Comment

by:viktornet
ID: 2698242
of course...


























....NOT ;)
0
 

Accepted Solution

by:
MaximW earned 20 total points
ID: 2711899
You should use IDSell COM obj to resolve path of the .lnk
Below is the sample.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ShlObj, ActiveX, ComObj, CommCtrl,ComCtrls, StdCtrls;

const
  SLR_NO_UI               = $0001;
  SLR_ANY_MATCH           = $0002;
  SLR_UPDATE              = $0004;

  SLGP_SHORTPATH          = $0001;
  SLGP_UNCPRIORITY        = $0002;

 {$IFDEF VER100}
   CLSID_ShellLink: TGUID = (D1:$00021401; D2:$0; D3:$0; D4:($C0,$0,$0,$0,$0,$0,$0,$46));
   IID_IShellLink: TGUID  = (D1:$000214EE; D2:$0; D3:$0; D4:($C0,$0,$0,$0,$0,$0,$0,$46));
  {$ELSE}
   CLSID_ShellLink: TCLSID = (D1:$00021401; D2:$0; D3:$0; D4:($C0,$0,$0,$0,$0,$0,$0,$46));
   IID_IShellLink: TCLSID  = (D1:$000214EE; D2:$0; D3:$0; D4:($C0,$0,$0,$0,$0,$0,$0,$46));
  {$ENDIF}
   IID_IPersistFile: TGUID = (
    D1:$0000010B;D2:$0000;D3:$0000;D4:($C0,$00,$00,$00,$00,$00,$00,$46));

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
function ResolveFileShortcut( FileName : String ) : String;
var
  HResx: HResult;
  psl: IShellLink;
  ppf: IPersistFile;
  PCLinkName: PChar;
  WCLinkName: array[0..Max_Path] of WideChar;
  Buf: array[0..255] of Char;
  IBuf: Integer;
  WBuf: Word;
  Data: TWin32FindData;
begin
  result:='';
  CoInitialize(nil);

  HResx := CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER,IID_IShellLink, psl);
  if not Succeeded(HResx) then exit;

  HResx := psl.QueryInterface(IID_IPersistFile, ppf);
  if not Succeeded(HResx) then exit;

  PCLinkName := StrAlloc(Length(FileName)+1);
  StrPCopy(PCLinkName, FileName);
  MultiByteToWideChar(CP_ACP, 0, PCLinkName, -1, WCLinkName, Max_Path);
  HResx := ppf.Load(WCLinkName, STGM_READ);
  if not Succeeded(HResx) then exit;

  psl.GetPath(@Buf, Max_Path, Data, SLGP_UNCPRIORITY);
  Result := StrPas(Buf);
  CoUninitialize;
  //ppf._Release;
  //psl._Release;
  StrDispose(PCLinkName);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
edit2.text:= ResolveFileShortCut(edit1.text);
end;
0
 

Expert Comment

by:MaximW
ID: 2711908
IDShell , sorry:)
you get the real file/dir path, so you can open it with usual opendir...
0
 

Expert Comment

by:MaximW
ID: 2720134
Thanks
0
 

Expert Comment

by:TedPark
ID: 11507540
Did anybody ever solve this?.
I have the same or similar problem, but none of the answers above works for me.
I have created a LNK to a BAT file, both on C:\.  I can launch the BAT correctly by double-clicking on either.
When using ShellExecute, as per above:
     ShellExecute(0, "open", "C:\XXX.BAT", NULL, NULL, SW_SHOW);
This works as expected.  With the following, nothing happens and no error is generated.
     ShellExecute(0, "open", "C:\XXX.BAT.lnk", NULL, NULL, SW_SHOW);
Furthermore, I have a second machine almost identical to the first (both with W2K) that works fine with either form.
On the first machine, "edit" doesn't work for the LNK either, but it works on the second machine.
Finally, using NULL instead of "open" works fine for both forms and for both machines.
This makes no sense to me, yet it is the truth.  I have seen several topics on EE that touch on this, but no solutions seen.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, MySQL Query 4 109
Print Graphic and Text to Epson TM-T88v 12 114
Working with hours 3 31
Delphi inherited method 6 40
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

21 Experts available now in Live!

Get 1:1 Help Now