Solved

command execprogram

Posted on 1998-09-14
12
348 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
 
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
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.

 
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

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
Intraweb submit form as a POST request 4 263
Using idhttp to login to instagram 2 76
Unique identifier on a terminal server (rdp) 4 46
DBGrid or StringGrid ? 6 70
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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