同意楼上,也可以
BOOL CreateProcess( LPCTSTR lpApplicationName, // pointer to name of executable module
LPTSTR lpCommandLine, // pointer to command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // pointer to process security attributes
LPSECURITY_ATTRIBUTES lpThreadAttributes, // pointer to thread security attributes
BOOL bInheritHandles, // handle inheritance flag
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // pointer to new environment block
LPCTSTR lpCurrentDirectory, // pointer to current directory name
LPSTARTUPINFO lpStartupInfo, // pointer to STARTUPINFO
LPPROCESS_INFORMATION lpProcessInformation // pointer to PROCESS_INFORMATION
);
BOOL CreateProcess( LPCTSTR lpApplicationName, // pointer to name of executable module
LPTSTR lpCommandLine, // pointer to command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // pointer to process security attributes
LPSECURITY_ATTRIBUTES lpThreadAttributes, // pointer to thread security attributes
BOOL bInheritHandles, // handle inheritance flag
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // pointer to new environment block
LPCTSTR lpCurrentDirectory, // pointer to current directory name
LPSTARTUPINFO lpStartupInfo, // pointer to STARTUPINFO
LPPROCESS_INFORMATION lpProcessInformation // pointer to PROCESS_INFORMATION
);
解决方案 »
- FLASH文件分析高速算法 欢迎大家使用
- 各位大哥请帮帮忙呀,关于存入图片路径的两个问题。
- 请问如何让程序运行时不在状态栏显示?
- 如何制作WINDOWS界面
- Windows Socket Error: (11001), on API 'Async Lookup'------200分
- Vc代码转Delphi代码的问题!急,在线等待!
- DBGRID提问
- 我是菜鸟,有个小问题
- 多层应用程序中,客户端和服务器端的联接的问题?
- 求dxDBTreeView 1.2 for Delphi 5
- 有关delphi6的打包问题
- 用TAdodataset + tdbgrid处理,如何获得已DELETE,但没有POST的记录?
True,就行了(别忘了设时间)
procedure ExecAndWait(const Filename, Params: string; WindowState: word; TimeLimit:double;var usetime:double);
{ 执行一个程序,并在timelimit内结束它 , 返回其运行时间}
{ filename 执行文件名 params 参数 windowstate 显示方式,通常SW_SHOWMINIMIZED
timelimit 时间限制 usetiem 返回程序运行的时间}
{ 注意要 uses WinTypes, WinProcs, StdCtrls; }
var
SUInfo: TStartupInfo;
ProcInfo: TProcessInformation;
CmdLine: string;
dwProc : THandle;
starttime:Tdatetime;
begin
{得到命令行}
{ Enclose filename in quotes to take care of long filenames with spaces. }
CmdLine := '"' + Filename + '"' + Params; {得到SUINfo}
FillChar(SUInfo, SizeOf(SUInfo), #0);
with SUInfo do
begin
cb := SizeOf(SUInfo);
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow := WindowState;
end; {建立一个进程}
CreateProcess(NIL, PChar(CmdLine), NIL, NIL, FALSE,
CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, NIL,
PChar(ExtractFilePath(Filename)), SUInfo, ProcInfo); { 执行并终止它 }
Starttime := now;
repeat
dwProc:=OpenProcess(PROCESS_ALL_ACCESS or PROCESS_TERMINATE,FALSE,dword(ProcInfo.dwProcessId));
sleep(50);
until ((now - starttime)*24*60*60>timelimit) or (dwProc = 0); usetime := (now-starttime)*24*60*60; {终止程序}
dwProc:=OpenProcess(PROCESS_ALL_ACCESS or PROCESS_TERMINATE,FALSE,dword(ProcInfo.dwProcessId));
terminateprocess(dwProc,0); { Clean up the handles. }
CloseHandle(ProcInfo.hProcess);
CloseHandle(ProcInfo.hThread);
end;