Improve company productivity with a Business Account.Sign Up

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

Alternative to WinExec

I need to start different programs from my own program.

I store the address to the programs in TFilename's.

What I do is this:
I have a variable (FileN) of TFilename.

if WinExec(PChar(FileN),SW_SHOW)<32 then
   begin
      messagedlg('error', mtInformation,[mbOk], 0)
   end;

But it only work for programs that does not access other files. It seems that the programs I load with WinExec search for the files they need in the folder of my program.

How do I tell them to act as if they were executed from their own folder?

0
retep
Asked:
retep
1 Solution
 
bogieman_Commented:
Tell us more about "But it only work for programs that does not access other files".  You might try using ShellExecute(...), but I don't know exactly what you mean.
0
 
bogieman_Commented:
Sorry, I just re-read your question and understand - I think ShellExecute works.
0
 
retepAuthor Commented:
Could you show me how ShellExecute works? And which unit I need to add in my uses-clause...

Thanks :)
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
bogieman_Commented:
If you have D2 or above, it's in the windows unit, which is in your uses clause as a default.  I can't remember the parameters - and I'm not on a computer with Delphi on at the moment, but search for it in the Win32.hlp help file.  I think it might go something like ShellExecute(handle,'c:\Game.exe','open'...).
0
 
edeyCommented:
there are also plenty of examples inthe ee paq's.

Gl
Mike
0
 
Grayl1Commented:
Hi!

Try using SW_NORMAL in stead of SW_SHOW...
0
 
retepAuthor Commented:
bogieman>> I have Delphi4, but it doesn't recognice ShellExecute(..) ???!

Anyone who knows how to use it?

Grayl1>> I have tried SW_NORMAL... No success...
0
 
DrDelphiCommented:
You have to to include ShellAPI in the uses section. From there the parameters are:
  ShellExecute(HWND,Operation,File,Parameters,Directory,ShowCmd);


For example to open a text file:

ShellExecute(handle,'open','sometextfile.txt',nil,nil,SW_ShowNormal);

Good luck!!

BTW, if you have a copy of the Delphi developer from January, I have an article in it that explains the things you can use the ShellAPI for.

0
 
DragonSlayerCommented:
In other words, don't pass a nil to the Directory parameter in ShellExecute, instead pass along the directory that you wish for the programme to start in.

Cheers,
DragonSlayer
0
 
retepAuthor Commented:
This was the closest I got to a whole answer. Therefore DrDelphi gets the points... Hope the rest of you doesn't feel to cheated...

Thanks to all of you.
Regards
Retep :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now