使用delphi应用程序打开外部应用程序并传递参数
实际上,我有一个自定义应用程序,希望将一些值传递给该.exe,然后它应该在某些事件上执行。它应该自动生成文件使用delphi应用程序打开外部应用程序并传递参数,delphi,exe,delphi-7,Delphi,Exe,Delphi 7,实际上,我有一个自定义应用程序,希望将一些值传递给该.exe,然后它应该在某些事件上执行。它应该自动生成文件 unit fExecuteExe; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ShellApi; type TForm1 = class(TForm) Button1: TButton;
unit fExecuteExe;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellApi;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
filename: String;
begin
filename := 'C:\Testsrc\MojaveD5\Tools\AliasToDataview\Alias2DV.exe';
ShellExecute(handle,'open',PChar(filename), '','',SW_SHOWNORMAL);
end;
end.
德尔福表格
object Form1: TForm1
Left = 179
Top = 116
Width = 495
Height = 294
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 176
Top = 96
Width = 113
Height = 25
Caption = 'Run Alias2Dataview'
TabOrder = 0
OnClick = Button1Click
end
end
有什么方法可以打开这个应用程序(下面提供的图像),并将一些值传递到它的文本框,然后单击它的按钮
此应用程序不支持命令行。不幸的是,我只有.exe,没有代码。首先不要使用ShellExecute,因为您不知道结果。你可以用
// Runs application and returns PID. 0 if failed.
function RunApplication(const AExecutableFile, AParameters: string;
const AShowOption: Integer = SW_SHOWNORMAL): Integer;
var
_SEInfo: TShellExecuteInfo;
begin
Result := 0;
if not FileExists(AExecutableFile) then
Exit;
FillChar(_SEInfo, SizeOf(_SEInfo), 0);
_SEInfo.cbSize := SizeOf(TShellExecuteInfo);
_SEInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
// _SEInfo.Wnd := Application.Handle;
_SEInfo.lpFile := PChar(AExecutableFile);
_SEInfo.lpParameters := PChar(AParameters);
_SEInfo.nShow := AShowOption;
if ShellExecuteEx(@_SEInfo) then
begin
WaitForInputIdle(_SEInfo.hProcess, 3000);
Result := GetProcessID(_SEInfo.hProcess);
end;
end;
若应用程序不支持任何命令行参数,那个么您可以自动执行所需的操作
例如:运行应用程序要等待其窗口出现。然后枚举子窗口,当您有句柄时,您可以执行所有操作:设置文本、单击按钮等。所有操作中的第一个都不使用ShellExecute,因为您不知道结果。你可以用
// Runs application and returns PID. 0 if failed.
function RunApplication(const AExecutableFile, AParameters: string;
const AShowOption: Integer = SW_SHOWNORMAL): Integer;
var
_SEInfo: TShellExecuteInfo;
begin
Result := 0;
if not FileExists(AExecutableFile) then
Exit;
FillChar(_SEInfo, SizeOf(_SEInfo), 0);
_SEInfo.cbSize := SizeOf(TShellExecuteInfo);
_SEInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
// _SEInfo.Wnd := Application.Handle;
_SEInfo.lpFile := PChar(AExecutableFile);
_SEInfo.lpParameters := PChar(AParameters);
_SEInfo.nShow := AShowOption;
if ShellExecuteEx(@_SEInfo) then
begin
WaitForInputIdle(_SEInfo.hProcess, 3000);
Result := GetProcessID(_SEInfo.hProcess);
end;
end;
若应用程序不支持任何命令行参数,那个么您可以自动执行所需的操作
例如:运行应用程序要等待其窗口出现。然后枚举子窗口,当您有句柄时,您可以执行所有操作:设置文本、单击按钮等。使用UI Automation实现自动化。使用UI Automation实现自动化。