Two methods of Delphi calling Cmd
Var
s:string;
Begin
s:= ' 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 run EXE files. such as: WinExec (' Notepad.exe Readme.txt ', sw_show);?
ShellExecute can run not only exe files, but also files that are already associated.
The first must refer to the Shellapi.pas unit: Uses SHELLAPI;?
1. Standard usage?
ShellExecute function prototype and parameter meaning are as follows:?
function ShellExecute (Hwnd:hwnd; Operation, FileName, Parameters,directory:pchar; Showcmd:integer): HINST; stdcall;?
HWnd: Used to specify the parent window handle. When an error occurs in the function call procedure, it acts as the parent window of the Windows message window. For example, you can set it as the Application main window handle
, which is application.handle, can also be set to the desktop window handle (obtained with the GetDesktopWindow function).
Operation: Used to specify the action to be made. Where the "open" operation means that the program specified by the filename parameter is executed, or the file or folder specified by the filename parameter is opened;
The "print" operation means that the file specified by the filename parameter is printed, and the "Explore" action indicates that the folder specified by the filename parameter is browsed. When the parameter is set to nil, it indicates that the default
Operation "Open".?
FileName: Used to specify the filename to open, the name of the program file to execute, or the folder name to browse.
Parameters: If the filename parameter is an executable program, this parameter specifies a command-line argument, 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 how the program window is initially displayed, otherwise this parameter should be set to 0.
If the ShellExecute function call succeeds, the return value is the instance handle of the executing program. If the return value is less than 32, it indicates an error occurred.
The above is only the standard usage of the ShellExecute function, and the following describes its special usage.
2. Special usage?
If the filename parameter is set to the "http:" protocol format, the function opens the default browser and links to the specified URL address. If multiple browsers are installed in the user's machine, the
The function determines which browser to start based on the settings of the HTTP protocol handler (Protocols Handler) in the Windows 9x/nt registry.
Format one:/HTTP website domain name.
e.g. ShellExecute (handle, ' open ', http://;? Www.neu.edu.cn ', nil, nil, SW_SHOWNORMAL);?
Format two: HTTP//Website name/page file name.
e.g. 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, the function launches the default mail client, such as Microsoft Outlook (also including Microsoft Outlook
EXDIVSS) or Netscape Messanger. If more than one mail client is installed in the user's machine, the function will be based on the settings of the Mailto protocol handler in the Windows 9x/nt Registry
Determine which mail client to start.
Format one: mailto:?
such as: ShellExecute (handle, ' open ', ' mailto: ', nil, nil, SW_SHOWNORMAL); Open the new mail window.
Format two: mailto: User account @ Mail server address?
such as: ShellExecute (handle, ' open ', ' mailto:[email protected]', nil, nil, SW_SHOWNORMAL); Opens a new mail window and automatically fills in the recipient's
Access. If you specify multiple recipient addresses, the recipient addresses must be separated by semicolons or commas (hereinafter).
Format three: mailto: User account @ Mail server address? subject= message subject &body= message body?
such as: ShellExecute (handle, ' open ', ' mailto:[email protected]? Subject=hello&body=this is a test ', nil, nil,
SW_SHOWNORMAL) opens a new mail window and automatically fills in the recipient's address, message subject, and message body. If the message body includes multiple lines of text, you must add a line break between each line of text
Escape character%0a.?
Example (Delphi):?
Call C:project1.exe in an application;?
ShellExecute (handle, ' open ', ' c:project1.exe ', ' string contents ', nil, SW_SHOWNORMAL);?
Can be called in Project1.exe:?
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, a command that specifies the visibility aspect of the window.
Please use any of the following constants?
Sw_hide hidden window, active state to make a window?
sw_minimize minimized window, active state to make a window?
Sw_restore Display a window with its original size and position, while making it active?
Sw_show Display a window with its current size and position, while making it active?
Sw_showmaximized to maximize the window and activate it?
sw_showminimized Minimize the window and activate it?
Sw_showminnoactive Minimize a window without changing the active window?
Sw_showna Display a window with the current size and position without changing the active window?
Sw_shownoactivate Display a window with the nearest size and position without changing the active window?
Sw_shownormal and Sw_restore the same > recently want to use Delphi to do a Apache+mysql integration environment to use the following knowledge
>
>delphi call the cmd file with this function
>
>winexec () function
>
> Example: I'm going to call ' E:\call.cmd this file
>
>winexec (' E:\call.cmd ', sw_hide);
>
>sw_show indicates that the running program window is activated at its current size and displayed.
>
>
> Loading Data ...
>
>
> The second parameter is how the main window of the control program is displayed
The possible values for the > second parameter are:
>sw_hide//Hide main window after program startup
>sw_maximize//Maximize operation
>sw_minimize//Minimized operation
>sw_restore//Restores the maximized or minimized window to normal
>sw_show//Show main window at current position and size
>sw_showmaximized//Activates the window and maximizes the operation
>sw_showminimized//Activate the window and run it minimized
>sw_showminnoactive//minimized operation, but not activated
>sw_shownoactivate//above the window size runs, but does not activate
>sw_shownormal//Normal mode, generally run with this? There are three API functions that can run executable files winexec, ShellExecute, and CreateProcess.
CreateProcess because of the use of complex, relatively less use.
>
>winexec mainly run EXE files. such as: WinExec (' Notepad.exe Readme.txt ', sw_show);?
>shellexecute can run not only exe files, but also files that are already associated.
> must first refer to the Shellapi.pas unit: Uses SHELLAPI;?
>
>1. Standard usage?
>shellexecute function prototype and parameter meaning are as follows:?
>function ShellExecute (Hwnd:hwnd; Operation, FileName, Parameters,directory:pchar; Showcmd:integer): HINST; stdcall;?
> hWnd: Used to specify the parent window handle. When an error occurs in the function call procedure, it acts as the parent window of the Windows message window. For example, you can set it as the Application main window handle
, which is application.handle, can also be set to the desktop window handle (obtained with the GetDesktopWindow function).
> Operation: Used to specify the action to be made. Where the "open" operation means that the program specified by the filename parameter is executed, or the file or folder specified by the filename parameter is opened;
The "print" operation means that the file specified by the filename parameter is printed, and the "Explore" action indicates that the folder specified by the filename parameter is browsed. When the parameter is set to nil, it indicates that the default
Operation "Open".?
> FileName: Used to specify the filename to open, the name of the program file to execute, or the folder name to browse.
> Parameters: If the filename parameter is an executable program, this parameter specifies a command-line argument, 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 how the program window is initially displayed, otherwise this parameter should be set to 0.
> If the ShellExecute function call succeeds, the return value is the instance handle of the executing program. If the return value is less than 32, it indicates an error occurred.
> The above is just the standard usage of the ShellExecute function, and the following describes its special usage.
>
>2. Special usage?
> If the filename parameter is set to the "http:" protocol format, the function opens the default browser and links to the specified URL address. If multiple browsers are installed in the user's machine, the
This function determines which browser to start based on the settings of the HTTP protocol handler (Protocols Handler) in the Windows 9x/nt registry.
> Format one: HTTP//website domain name.
> such as: ShellExecute (handle, ' open ',/http; Www.neu.edu.cn ', nil, nil, SW_SHOWNORMAL);?
> Format II:/HTTP/Website name/page name.?
> such as: ShellExecute (handle, ' open ',/http; Www.neu.edu.cn/default.htm ', nil,nil,?sw_shownormal);?
> If the filename parameter is set to the "mailto:" protocol format, the function launches the default mail client, such as Microsoft Outlook (also including Microsoft Outlook
EXDIVSS) or Netscape Messanger. If more than one mail client is installed in the user's machine, the function will be based on the settings of the Mailto protocol handler in the Windows 9x/nt Registry
Determine which mail client to start.
> Format one: mailto:?
> such as: ShellExecute (handle, ' open ', ' mailto: ', nil, nil, SW_SHOWNORMAL); Open the new mail window.
> Format II: mailto: User account @ Mail server address?
> such as: ShellExecute (handle, ' open ', ' mailto:[email protected]', nil, nil, SW_SHOWNORMAL); Open the new mail window and fill in the recipients automatically
Address. If you specify multiple recipient addresses, the recipient addresses must be separated by semicolons or commas (hereinafter).
> Format three: mailto: User account @ Mail server address? subject= message subject &body= message body?
> such as: ShellExecute (handle, ' open ', ' mailto:[email protected]? Subject=hello&body=this is a test ', nil, nil,
SW_SHOWNORMAL) opens a new mail window and automatically fills in the recipient's address, message subject, and message body. If the message body includes multiple lines of text, you must add a line break between each line of text
Escape character%0a.?
> Example (Delphi):?
> Call C:project1.exe in an application;?
>shellexecute (handle, ' open ', ' c:project1.exe ', ' string contents ', nil, SW_SHOWNORMAL);?
> can be called in Project1.exe:?
>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, a command that specifies the visibility aspect of the window.
> Please use any of the following constants?
>sw_hide hidden window, active state to make a window?
>sw_minimize minimized window, active state to make a window?
>sw_restore Display a window with its original size and position, while making it active?
>sw_show Display a window with its current size and position, while making it active?
>sw_showmaximized to maximize the window and activate it?
>sw_showminimized Minimize the window and activate it?
>sw_showminnoactive Minimize a window without changing the active window?
>sw_showna Display a window with the current size and position without changing the active window?
>sw_shownoactivate Display a window with the nearest size and position without changing the active window?
>sw_shownormal is the same as Sw_restore
Go Two methods of Delphi calling Cmd