Solved

command execprogram

Posted on 1998-09-14
12
352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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