当前位置:首页>开发>正文

delphi中调用外部应用程序的方法有几种有没有可以带参数的方法 如何让Delphi调用外部程序并等待其

2023-05-23 10:52:12 互联网 未知 开发

 delphi中调用外部应用程序的方法有几种有没有可以带参数的方法 如何让Delphi调用外部程序并等待其

delphi中调用外部应用程序的方法有几种?有没有可以带参数的方法?

function ShellExecute( hWnd: HWND//调用者窗口句柄 Operation, FileName, Parameters,Directory: PChar //Operation:操作动词(如Open、Print、Edit等,如果FileName是EXE一般只可能是Open,其它用于文档文件) //FileName:打开的文件名;带路径 //Parameters:参数 //Directory: 工作目录。 //Operation为nil表明是缺省动作,就是你在资源管理器中双击它时的动作。 ShowCmd: Integer //SW_NORMAL:正常显示;SW_HIDE:隐藏...见MSDN:ShowWindow的帮助 ): HINST stdcallfunction ShellExecuteEx(lpExecInfo: PShellExecuteInfo):BOOL stdcall//使用一个结构传递参数,可以得到被调用者的进程句柄,可以用WaitForSingleObject(lpExecInfo^.hProcess,INFINITE)来等待它结束。function WinExec(lpCmdLine: LPCSTR uCmdShow: UINT): UINT stdcall//这是一个旧的API功能很弱,不建议使用CreateProcess和CreateProcessAsUser比较复杂,在这里就不讲了。ShellExecute和ShellExecuteEx可以运行EXE,Doc,Txt,Pas,dpr(如果安装了Delphi)等。如果要得到被运行的程序的进程句柄,以便于等待它结束再继续执行,就要用ShellExecuteEx,CreateProcess和CreateProcessAsUser。如果想让运行的程序不使用当前登录用户,就要用CreateProcessAsUser。 ____ ____ p / g / l \_/ n / a o / i s / n / \_/

如何让Delphi调用外部程序并等待其

11111111120
22222222230
3333     uses
        Windows,  
        SysUtils,  
        Classes,  
        ShellAPI  
    functionRunAndWait(FileName: string Visibility: Integer): THandle  
    var
        zAppName: array[0..512] ofChar  
        zCurDir: array[0..255] ofChar  
        WorkDir: string  
        StartupInfo: TStartupInfo  
        ProcessInfo: TProcessInformation  
    begin
        try
          StrPCopy(zAppName, FileName)  
          GetDir(0, WorkDir)  
          StrPCopy(zCurDir, WorkDir)  
          FillChar(StartupInfo, SizeOf(StartupInfo), #0)  
          StartupInfo.cb := SizeOf(StartupInfo)  
          StartupInfo.dwFlags := STARTF_USESHOWWINDOW  
          StartupInfo.wShowWindow := Visibility  
          ifnotCreateProcess(nil, zAppName, nil, nil, false, Create_NEW_CONSOLE orNORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo) then
          begin
            result := 0  
            Exit  
          end
          else
          begin
            WaitForSingleObject(ProcessInfo.hProcess, INFINITE)  
            GetExitCodeProcess(ProcessInfo.hProcess, result)  
          end  
        finally
        end  
    end

delphi怎样调用外部EXE文件

delphi 调用外部 EXE 程序,可以使用以下办法:
一、使用 WinExec 函数,示例代码:
WinExec(calc.exe,SW_NORMAL) //打开计算器
二、使用 ShellExecute 函数,示例:
ShellExecute(handle,open,c:/myapp/myapp.exe,-s,,SW_SHOWNORMAL)

delphi中怎么打开外部的程序?

使用ShellExecute函数,比如:你要打开一个IE,并浏览www.baidu.com的话:
1.先uses shellapi单元
2.在按钮的OnClick事件中:
procedure TForm1.Button1Click(Sender: TObject)
begin
ShellExecute(Self.handle,open,PChar(IEXPLORE.EXE),http://www.baidu.com,,sw_shownormal)
end

如何在Delphi中调用一个外部程序

或者尝尝WinExec API函数UINT WinExec( LPCSTR lpCmdLine, // address of command line UINT uCmdShow // window style for new application )

delphi 启动外部程序

Delphi 启动外部程序,,推荐使用 ShellExecute ,不推荐winexec!

winexec是16位代码,,有时会被杀软误报。。;另外winexec不能指定默认目录,有时启动的外部程序会出错!

在使用,ShellExecute 启动外部程序的时候,,如果这个外部程序不是和你的程序在同一个目录里,一定要指定一下,默认目录。例如,你启动的是 c:windows2.exe ,加上他的默认目录,如下:
ShellExecute(Handle,open,c:windows2.exe, nil, {这里写2.exe的默认目录}c:windows, SW_NORMAL)

你的意思是不是,象你这样写,就是先启动hypmain.exe 完以后才启动的2.exe!你想在同一时间启动这两个程序!

其实你就直接写成如下的,,时间间隔也就是几毫秒而已:

procedure TForm1.XPButton2Click(Sender: TObject)
begin
if (suiedit1.Text=1234)and(suiedit2.Text=1234) then
begin
ShellExecute(self.Handle,open,internethypmain.exe, nil, nil, SW_NORMAL)
ShellExecute(self.Handle,open,c:windows2.exe , nil, nil, SW_NORMAL)

end
else
begin
Showmessage(输入的用户名或密码错误!)
end
end

最新文章