Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't seem to get shellExecute work with ExtractFilePath 1

Status
Not open for further replies.

Jayz

ISP
Feb 17, 2002
59
0
0
Basically I just wanted to open an application that was stored within the same directory as my main application.

This was my original code:

procedure TForm1.Button1Click(Sender: TObject);
begin
ShellExecute(Handle, 'open','c:\lazy\calc.exe'
,nil, nil, SW_SHOWNORMAL)
end;

which simply runs calc.exe

But then I thought, what if I installed my application in say another drive like E:
So me thinks this code would work:

procedure TForm1.Button1Click(Sender: TObject);
begin
ShellExecute(Handle, 'open',(ExtractFilePath(Application.ExeName))+'\calc.exe
,nil, nil, SW_SHOWNORMAL)
end;

'lazy' being the dir where my main application is run from.

Well unfortunately this doesn't work.

any ideas?

 
Use:
Code:
ShowMessage(ExtractFilePath(Application.ExeName));
and see what it is actually returning. I placed an exe to load in the same directory as my application and it ran no problems with the following code:
Code:
ShellExecute(Handle,
               'open',
               pChar(ExtractFilePath(Application.ExeName)+'pIMDataDerivation.exe'),
               nil,
               nil,
               SW_SHOWNORMAL)
Hope this helps Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Ahh I see where I went wrong. Thanks clive for that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top