Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 392
  • Last Modified:

Shell execute

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
cookey
Asked:
cookey
  • 5
  • 3
  • 3
  • +7
1 Solution
 
mhervaisCommented:
litening
0
 
MotazCommented:
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
 
rene100Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
MadshiCommented:
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
 
intheCommented:
i think Motaz has answered problem..
0
 
cookeyAuthor Commented:
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
 
cookeyAuthor Commented:
OK, Thanks for everybody, I have been solved it myself, thanks very much
0
 
simonetCommented:
>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
 
MadshiCommented:
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
 
viktornetCommented:
How is it going guys?
0
 
intheCommented:
hehe big hello to you viktor ;-)
been in hiding ?




0
 
viktornetCommented:
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
 
intheCommented:
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
 
viktornetCommented:
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
 
MotazCommented:
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
 
simonetCommented:
Yo Victor! How's everything, pal?!

Alex
0
 
viktornetCommented:
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
 
simonetCommented:
I hope you have not joined the dark side... er... Visual Basic!

0
 
viktornetCommented:
of course...


























....NOT ;)
0
 
MaximWCommented:
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
 
MaximWCommented:
IDShell , sorry:)
you get the real file/dir path, so you can open it with usual opendir...
0
 
MaximWCommented:
Thanks
0
 
TedParkCommented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
  • 3
  • +7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now