?
Solved

Shell execute

Posted on 2000-04-07
23
Medium Priority
?
386 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 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