Two Methods for Delphi to call cmd

Source: Internet
Author: User
Tags microsoft outlook

Two Methods for Delphi to call cmd
VaR
S: string;
Begin
S: Your 'cmd.exe/C' + edit1.text + '> C: \ 1.txt ';
Winexec (pchar (s), sw_hide );
Sleep (2000 );
Memo1.lines. loadfromfile ('C: \ 1.txt ');

2
Shellexecute(handle,nil,'cmd.exe ', pchar (form2.edit1. Text), nil, sw_hide );
Winexec mainly runs the EXE file. For example, winexec('notepad.exe readme.txt ', sw_show );?
ShellExecute can run not only EXE files, but also associated files.
First, you must reference the shellapi. Pas unit: Uses shellapi ;?

1. Standard usage?
The meanings of the ShellExecute Function prototype and parameters are as follows :?
Function ShellExecute (hwnd: hwnd; operation, filename, parameters, directory: pchar; showcmd: integer): hinst; stdcall ;?
● Hwnd: Specifies the parent window handle. When an error occurs during a function call, it is used as the parent window of the Windows message window. For example, you can set it as an application.ProgramMain Window handle

That is, application. Handle. You can also set it as a desktop window handle (obtained using the getdesktopwindow function ).?
● Operation: Specifies the operation to be performed. The "open" operation indicates executing the program specified by the filename parameter or opening the file or folder specified by the filename parameter;

The "print" Operation prints the Files specified by the filename parameter, and the "Browse e" Operation displays the folders specified by the filename parameter. If the parameter is set to nil

Recognize "open ".?
● Filename: used to specify the name of the file to be opened, the name of the program file to be executed, or the name of the folder to be browsed .?
● Parameters: If the filename parameter is an executable program, this parameter specifies the command line parameter. Otherwise, this parameter should be nil or pchar (0 ).?
● Directory: used to specify the default directory .?
● Showcmd: If the filename parameter is an executable program, this parameter specifies the initial display mode of the program window. Otherwise, this parameter should be set to 0 .?
If the ShellExecute Function is successfully called, the returned value is the instance handle of the executed program. If the returned value is less than 32, an error occurs .?
The above is only the standard usage of the ShellExecute Function. The following describes its special usage .?

2. Special usage?
If you set the filename parameter to the "http:" protocol format, this function opens the default browser and links to the specified URL address. If multiple browsers are installed on your machine

The function determines which browser to start based on the settings of the HTTP handler (Protocols handler) in the Windows 9x/NT Registry .?
Format 1: http: // website domain name .?
Example: ShellExecute (handle, 'open', http ://;? Www.neu.edu.cn ', nil, nil, sw_shownormal );?
Format 2: http: // website domain name/Webpage file name .?
Example: ShellExecute (handle, 'open', http ://;? Www.neu.edu.cn/default.htm', nil,nil ,? Sw_shownormal );?
If you set the filename parameter to the "mailto:" protocol format, this function starts the default mail client program, such as Microsoft Outlook (including Microsoft Outlook

Exdivss) or Netscape Messanger. If you have installed multiple email client programs on your machine, this function is based on the settings of the mailto protocol handler in the Windows 9x/NT Registry.

Are you sure you want to start the email client program .?
Format 1: mailto :?
Example: ShellExecute (handle, 'open', 'mailto: ', nil, nil, sw_shownormal); open the new mail window .?
Format 2: mailto: User Account @ email server address?
Example: ShellExecute (handle, 'open', 'mailto: who@mail.neu.edu.cn ', nil, nil, sw_shownormal); open the new mail window and automatically fill in the Recipient location

Address. If multiple recipient addresses are specified, the recipient addresses must be separated by semicolons or commas (, the same below ).?
Format 3: mailto: User Account @ email server address? Subject = Email Subject & Body = Email body?
Example: ShellExecute (handle, 'open', 'mailto: who@mail.neu.edu.cn? Subject = Hello & Body = This is a test ', nil, nil,

Sw_shownormal); opens the new mail window and automatically fills in the recipient address, subject, and body. If the mail body contains multiple lines of text, a line break must be added between each line of text.

Escape Character % 0a .?
Example (Delphi ):?
Call C: project1.exe;? In an application ;?
ShellExecute (handle, 'open', 'c: project1.exe ', 'string content', nil, sw_shownormal );?
In project1.exe, you can call :?
Procedure tform1.formcreate (Sender: tobject );?
VaR I: integer ;?
Begin?
For I: = 1 to paramcount do?
If paramstr (I) <> ''then showmessage (paramstr (I ));?
End;

The last parameter specifies the visibility command for the window .?
Please use any of the following constants?
Sw_hide hides the window, and the activity status gives a window?
Sw_minimize minimizes the window, and the active status gives a window?
Sw_restore displays a window with the original size and position, and enables it to enter the active status?
Sw_show displays a window with the current size and position, and enables it to enter the active status?
How does sw_showmaximized maximize the window and activate it?
Sw_showminimized minimizes the window and activates it?
Sw_showminnoactive minimizes a window without changing the activity window?
Sw_showna displays a window with the current size and position without changing the activity window?
Sw_shownoactivate displays a window with the latest size and position without changing the activity window?
Sw_shownormal is the same as sw_restore.> recently, I want to use Delphi to build an Apache + MySQL integrated environment. The following knowledge is used:
>
> Delphi calls the CMD file to use this function.
>
> Winexec () function
>
> Example: I want to call the file 'e: \ call. cmd.
>
> Winexec ('e: \ call. cmd', sw_hide );
>
> Sw_show indicates the program window activated with the current size and displayed.
>
>
> Loading data ......
>
>
> The second parameter is the display mode of the Main Window of the control program.
> The second parameter may take the following values:
> Sw_hide // hide the main window after the program is started
> Sw_maximize // maximize running
> Sw_minimize // minimize run
> Sw_restore // restore the maximized or minimized window to normal
> Sw_show // display the main window at the current position and size
> Sw_showmaximized // activate the window and maximize running
> Sw_showminimized // activate the window and minimize the running
> Sw_showminnoactive // The operation is minimized, but not activated.
> Sw_shownoactivate // The preceding window size is run but not activated.
> Sw_shownormal // common mode, which is usually used during running? There are three API functions that can run the executable files winexec, ShellExecute, and CreateProcess.

Because of its complexity, CreateProcess is rarely used .?
>
> Winexec mainly runs the EXE file. For example, winexec('notepad.exe readme.txt ', sw_show );?
> ShellExecute can run not only EXE files, but also associated files.
> First, you must reference the shellapi. Pas unit: Uses shellapi ;?
>
> 1. Standard usage?
> The meanings of the ShellExecute Function prototype and parameters are as follows :?
> Function ShellExecute (hwnd: hwnd; operation, filename, parameters, directory: pchar; showcmd: integer): hinst; stdcall ;?
> ● Hwnd: Specifies the parent window handle. When an error occurs during a function call, it is used as the parent window of the Windows message window. For example, you can set it as the application Main Window handle.

That is, application. Handle. You can also set it as a desktop window handle (obtained using the getdesktopwindow function ).?
> ● Operation: used to specify the operation to be performed. The "open" operation indicates executing the program specified by the filename parameter or opening the file or folder specified by the filename parameter;

The "print" Operation prints the Files specified by the filename parameter, and the "Browse e" Operation displays the folders specified by the filename parameter. If the parameter is set to nil

Recognize "open ".?
> ● Filename: used to specify the name of the file to be opened, the name of the program file to be executed, or the name of the folder to be browsed .?
> ● Parameters: If the filename parameter is an executable program, this parameter specifies the command line parameter. Otherwise, this parameter should be nil or pchar (0 ).?
> ● Directory: used to specify the default directory .?
> ● Showcmd: If the filename parameter is an executable program, this parameter specifies the initial display mode of the program window. Otherwise, this parameter should be set to 0 .?
> If the ShellExecute Function is successfully called, the returned value is the instance handle of the executed program. If the returned value is less than 32, an error occurs .?
> The above is only the standard usage of the ShellExecute Function. The following describes its special usage .?
>
> 2. Special usage?
> If you set the filename parameter to the "http:" protocol format, this function opens the default browser and links to the specified URL address. If multiple browsers are installed on your machine

This function determines which browser to start based on the settings of the HTTP handler (Protocols handler) in the Windows 9x/NT Registry .?
> Format 1: http: // website domain name .?
> For example: ShellExecute (handle, 'open', http ://;? Www.neu.edu.cn ', nil, nil, sw_shownormal );?
> Format 2: http: // website domain name/Webpage file name .?
> For example: ShellExecute (handle, 'open', http ://;? Www.neu.edu.cn/default.htm', nil,nil ,? Sw_shownormal );?
> If you set the filename parameter to the "mailto:" protocol format, this function starts the default mail client program, such as Microsoft Outlook (including Microsoft Outlook

Exdivss) or Netscape Messanger. If you have installed multiple email client programs on your machine, this function is based on the settings of the mailto protocol handler in the Windows 9x/NT Registry.

Are you sure you want to start the email client program .?
> Format 1: mailto :?
> For example, ShellExecute (handle, 'open', 'mailto: ', nil, nil, sw_shownormal); opens a new mail window .?
> Format 2: mailto: User Account @ email server address?
> For example: ShellExecute (handle, 'open', 'mailto: who@mail.neu.edu.cn ', nil, nil, sw_shownormal); open a new mail window and automatically fill in the recipient

Address. If multiple recipient addresses are specified, the recipient addresses must be separated by semicolons or commas (, the same below ).?
> Format 3: mailto: User Account @ email server address? Subject = Email Subject & Body = Email body?
> For example: ShellExecute (handle, 'open', 'mailto: who@mail.neu.edu.cn? Subject = Hello & Body = This is a test ', nil, nil,

Sw_shownormal); opens the new mail window and automatically fills in the recipient address, subject, and body. If the mail body contains multiple lines of text, a line break must be added between each line of text.

escape character % 0a .?
example (Delphi ):?
call C: project1.exe in an application ;?
ShellExecute (handle, 'open', 'c: project1.exe ', 'string content', nil, sw_shownormal );?
In project1.exe, you can call :?
procedure tform1.formcreate (Sender: tobject );?
var I: integer ;?
begin?
for I: = 1 to paramcount do?
If paramstr (I) <> ''then showmessage (paramstr (I ));?
end;
the last parameter specifies a visual command for the window .?
Please use any of the following constants?
sw_hide hides the window. Does the activity status give a window?
sw_minimize minimizes the window, and the activity status gives a window?
sw_restore displays a window with the original size and position, and enables it to enter the active status at the same time?
sw_show displays a window with the current size and position, and enables it to enter the active status at the same time?
sw_showmaximized maximize window and activate it?
sw_showminimized minimizes the window and activates it?
sw_showminnoactive minimizes a window without changing the activity window?
sw_showna displays a window with the current size and position without changing the activity window?
sw_shownoactivate displays a window with the nearest size and position without changing the activity window?
sw_shownormal is the same as sw_restore

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.