Solved

command execprogram

Posted on 1998-09-14
12
351 Views
Last Modified: 2008-01-16
does anybody know whats wrong, if delphi 2.0 doesn´t know this (macro)command?
0
Comment
Question by:wk51
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1339662
wk51,

don't know about execprogram. Why not using ShellExecuteEx or CreateProcess?

Regards, Madshi.
0
 
LVL 1

Expert Comment

by:duke_n
ID: 1339663
or Winexec?
0
 
LVL 1

Expert Comment

by:duke_n
ID: 1339664
don't forget to add ShellAPI to the uses list to use functions Madshi and I gave you.
0
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.

 
LVL 10

Expert Comment

by:viktornet
ID: 1339665
WinExec() was good to use in the 16-bit, but now there is ShellExecute() as Madshi gave you which is the easiest one to use... but as I've heard CreateProcess() is the best for use . o O

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339666
WinExec() was good to use in the 16-bit, but now there is ShellExecute() as Madshi gave you which is the easiest one to use... but as I've heard CreateProcess() is the best for use . o O

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339667
There is also another procedure, which is not that much used...

ExecuteFile()

Regards,
Viktor Ivanov
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1339668
viktornet,

I don't like CreateProcess because I think it can't execute files (e.g. "bitmap.bmp"). So I'm using ShellExecuteEx all the time. And it works perfectly. Why should CreateProcess be better?

Regards, Madshi.
0
 
LVL 2

Author Comment

by:wk51
ID: 1339669
i´ve tied winexec, but curiously works only on second run!
how is the syntax for createprocess or shellexecute(ex) i. e. to run "sol.exe" as normal window, and get the handle?
0
 
LVL 20

Accepted Solution

by:
Madshi earned 20 total points
ID: 1339670
wk51,

function ExecutePrgOrFile(prgOrFile, params, workingDir: string; var processHandle: cardinal) : boolean;
var ei : TShellExecuteInfo;
begin
  processHandle:=INVALID_HANDLE_VALUE;
  with ei do begin
    cbSize:=SizeOf(ei);
    fMask:=SEE_MASK_FLAG_NO_UI or SEE_MASK_NOCLOSEPROCESS;
    WND:=Application.handle;
    lpVerb:='Open';
    lpFile:=PChar(prgOrFile);
    lpParameters:=PChar(params);
    if workingDir='' then workingDir:=ExtractFilePath(prgOrFile);
    lpDirectory:=PChar(workingDir);
    nShow:=SW_SHOWNORMAL;
  end;
  result:=ShellExecuteEx(@ei);
  if result then processHandle:=ei.hProcess;
end;

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1339671
Sorry, forgotten your example:

if ExecutePrgOrFile('c:\windows\sol.exe','','',ph) then ...
0
 
LVL 2

Author Comment

by:wk51
ID: 1339672
a little bit overdressed, but works.
will give extra points to a followed question:
i´ve tried (as i´ve done before in vb) to look at later times with getmodulehandle if the application is running or closed at the meantime, but once again ... doesn´t work. I´ve found at help a function openprocess which might be an alternative but i´m not sure. what´s wrong with getmodulehandle or another way to test for an application identified by name or handle?

thanks to all contributions
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1339673
wk51,

what do you mean with overdressed? I just copied the function from my own tool collection. It's thought to fit several situations so it's a little bit more complex/flexible. Is it that what you mean?
Call WaitForSingleObject(processHandle). But this win API function hangs around. It return just after the process is closed. So if you should not call it in your main thread. Better create a TThread object that does nothing (in it's execute method) but call WaitForSingleObject.

Regards, Madshi.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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