Solved

command execprogram

Posted on 1998-09-14
12
350 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

786 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