扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
图1 添加组件后的窗体 |
procedure TForm1.btnWinExecClick(Sender: TObject); begin WinExec(’Notepad.exe’,SW_MAXIMIZE); end; |
procedure TForm1.btnShellExecuteClick(Sender: TObject); begin ShellExecute(Application.Handle,’Open’,’NotePad.exe’,PChar(’C:\AutoExec.bat’),nil,SW_SHOWNORMAL); end; |
PI:TProcessInformation; SI:TStartUpInfo; MyHandle:Thandle; |
procedure TForm1.btnCreateProcessOpenClick(Sender: TObject); begin FillChar(SI,sizeof(SI),#0); with SI do begin cb:=sizeof(SI); dwFlags:=StartF_UsesTDHandles or STARTF_USESHOWWINDOW; lptitle:=nil; wShowWindow:=SW_Show; end; CreateProcess(PChar(’C:\WINNT\Notepad.exe’), nil,nil,nil,true,DETACHED_PROCESS,nil,nil,SI,PI); end; |
procedure TForm1.btnCreateProcessCloseClick(Sender: TObject); begin MyHandle:=OpenProcess(PROCESS_ALL_ACCESS, FALSE,PI.dwProcessId); TerminateProcess(MyHandle,0); end; |
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ShellAPI; type TForm1 = class(TForm) btnWinExec: TButton; btnCreateProcessOpen: TButton; btnCreateProcessClose: TButton; btnShellExecute: TButton; procedure btnWinExecClick(Sender: TObject); procedure btnCreateProcessOpenClick(Sender: TObject); procedure btnCreateProcessCloseClick(Sender: TObject); procedure btnShellExecuteClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; PI:TProcessInformation; SI:TStartUpInfo; MyHandle:Thandle; implementation {$R *.dfm} procedure TForm1.btnWinExecClick(Sender: TObject); begin WinExec(’Notepad.exe’,SW_MAXIMIZE); end; procedure TForm1.btnCreateProcessOpenClick(Sender: TObject); begin FillChar(SI,sizeof(SI),#0); with SI do begin cb:=sizeof(SI); dwFlags:=StartF_UsesTDHandles or STARTF_USESHOWWINDOW; lptitle:=nil; wShowWindow:=SW_Show; end; CreateProcess(PChar(’C:\WINNT\Notepad.exe’),nil,nil,nil,true,DETACHED_PROCESS,nil,nil,SI,PI); end; procedure TForm1.btnCreateProcessCloseClick(Sender: TObject); begin MyHandle:=OpenProcess(PROCESS_ALL_ACCESS, FALSE,PI.dwProcessId); TerminateProcess(MyHandle,0); //关闭进程 end; procedure TForm1.btnShellExecuteClick(Sender: TObject); begin ShellExecute(Application.Handle,’Open’,’NotePad.exe’,PChar(’C:\AutoExec.bat’),nil,SW_SHOWNORMAL); end; end. |
图2 程序运行的初始画面 |
图3 程序运行结果 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者