Executeprocess-with command line support

Source: Internet
Author: User

Executeprocess-with command line support

This proc is a Delphi wrapper around und
The Win32 API "CreateProcess". It is
A better idea to use this instead
ShellExecute or other 16-bit functions when you're program is
Run in a 32-bit environment

 
Procedure executeprocess (filename: string;
Params: string; show: integer );
VaR
Startupinfo: tstartupinfo;
Processinfo: tprocessinformation;
Begin
If Params [1] <> ''then
Params: = ''+ Params;
Fillchar (startupinfo, sizeof (tstartupinfo), 0 );
With startupinfo do
Begin
CB: = sizeof (tstartupinfo );
Dwflags: = startf_useshowwindow;
Wshowwindow: = show;
End;

If not (CreateProcess (pchar (filename), pchar (Params ),
Nil, nil, false, normal_priority_class,
Nil, nil, startupinfo, processinfo ))
Then
Raiselastwin32error;
End;

// Modified version of executeprocess that works
// A command-line parameter

procedure executeprocess (filename,
Params: string;
show: integer);
var
startupinfo: tstartupinfo;
processinfo: tprocessinformation;
begin
Params: = trim (Params);
If Params <> ''then
filename: = filename + ''+ Params;

getstartupinfo (startupinfo);
with startupinfo do begin
CB: = sizeof (tstartupinfo);
dwflags: = startf_useshowwindow;
wshowwindow: = show;
end;
if not (CreateProcess (nil, pchar (filename), nil,
nil, false, normal_priority_class, nil,
nil, startupinfo, processinfo)
then
raiselastwin32error; // from sysutils Unit
end;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.