Solved

Alternative to WinExec

Posted on 2000-05-05
10
1,090 Views
Last Modified: 2010-04-04
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
Comment
Question by:retep
10 Comments
 
LVL 1

Expert Comment

by:bogieman_
ID: 2781174
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
 
LVL 1

Expert Comment

by:bogieman_
ID: 2781180
Sorry, I just re-read your question and understand - I think ShellExecute works.
0
 

Author Comment

by:retep
ID: 2781248
Could you show me how ShellExecute works? And which unit I need to add in my uses-clause...

Thanks :)
0
 
LVL 1

Expert Comment

by:bogieman_
ID: 2781299
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
 
LVL 6

Expert Comment

by:edey
ID: 2781397
there are also plenty of examples inthe ee paq's.

Gl
Mike
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:Grayl1
ID: 2781431
Hi!

Try using SW_NORMAL in stead of SW_SHOW...
0
 

Author Comment

by:retep
ID: 2781466
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
 
LVL 6

Accepted Solution

by:
DrDelphi earned 50 total points
ID: 2781726
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
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 2783232
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
 

Author Comment

by:retep
ID: 2783724
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
System restore point 4 91
Communication Between RC4 Delphi <-> PHP 3 101
creating threads in delphi 1 84
Performance of SQL statement 37 101
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

861 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

23 Experts available now in Live!

Get 1:1 Help Now