Solved

command execprogram

Posted on 1998-09-14
12
347 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
Comment Utility
wk51,

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

Regards, Madshi.
0
 
LVL 1

Expert Comment

by:duke_n
Comment Utility
or Winexec?
0
 
LVL 1

Expert Comment

by:duke_n
Comment Utility
don't forget to add ShellAPI to the uses list to use functions Madshi and I gave you.
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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
Comment Utility
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
Comment Utility
There is also another procedure, which is not that much used...

ExecuteFile()

Regards,
Viktor Ivanov
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, forgotten your example:

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

Author Comment

by:wk51
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

16 Experts available now in Live!

Get 1:1 Help Now