打开记事本,并打开一个文件(系统能识别记事本应用程序的路径,因此我们不必使用绝对路径) ShellExecute(Handle, 'open', PChar('notepad'), PChar('c:\test\readme.txt'), nil, SW_SHOW); HINSTANCE ShellExecute( HWND hwnd, // handle to parent window LPCTSTR lpOperation, // pointer to string that specifies operation to perform LPCTSTR lpFile, // pointer to filename or folder name string LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters LPCTSTR lpDirectory, // pointer to string that specifies default directory INT nShowCmd // whether file is shown when opened )
googel: WinExec ShellExecute
ShellExecute很方便,而且能够完成你的要求
Use shellAPI; shellexecute(handle,'open',pchar(ExtractFilePath(Paramstr(0))+'Help.CHM'),nil,nil,sw_shownormal);
ShellExecute(Handle, 'open', PChar('notepad'), PChar('c:\test\readme.txt'), nil, SW_SHOW);
HINSTANCE ShellExecute(
HWND hwnd, // handle to parent window
LPCTSTR lpOperation, // pointer to string that specifies operation to perform
LPCTSTR lpFile, // pointer to filename or folder name string
LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters
LPCTSTR lpDirectory, // pointer to string that specifies default directory
INT nShowCmd // whether file is shown when opened
)
ShellExecute
shellexecute(handle,'open',pchar(ExtractFilePath(Paramstr(0))+'Help.CHM'),nil,nil,sw_shownormal);
2.ShellExecute
3.CreateProcess
//创建进程并在3秒后杀掉它
procedure TForm1.Button2Click(Sender: TObject);
var
si:STARTUPINFO;
pi:PROCESS_INFORMATION;
begin
FillChar(si, SizeOf(si),0);
si.dwFlags := STARTF_USESHOWWINDOW;
si.cb:=SizeOf(si);
si.wShowWindow := SW_Show;
CreateProcess(0,'calc.exe',nil, nil, False,NORMAL_PRIORITY_CLASS, nil, nil,si,pi);
CloseHandle(pi.hProcess);
Sleep(3000);
TerminateProcess(OpenProcess(PROCESS_ALL_ACCESS,FALSE,pi.dwProcessId),0);
end;
ShellExecute(Handle,'open','gpedit.msc','','',SW_SHOW);
WinExec(PChar('cmd /C start http://www.baidu.com/'), SW_HIDE); 看看打开了没有。
如果没有特殊需求,WinExec配合start效果就不错了。