如何启动一个程序并得到进程号
编号:QA001232
建立日期: 1999年6月23日 最后修改日期:1999年6月23日
所属类别:
邓建松:
操作系统:WIN95
语言:DELPHI4.0
我在学习DELPHI4.0,其中用winexec函数启动一个程序,我想知道这个程序的进程号,不知如何取得,VB中的shell函数返回的是进程号,DELPHI4.0有没有这样的函数?请给出例了!不胜感谢!
回答:
你可以利用API函数CreateProcess,如:
var
zAppName:array[0..512] of char;
zCurDir:array[0..255] of char;
WorkDir:String;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
begin
StrPCopy(zAppName,'Write.exe');
GetDir(0,WorkDir);
StrPCopy(zCurDir,WorkDir);
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := SW_SHOW;
CreateProcess(nil,
zAppName, { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
false, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name }
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo);
ProcessInfo.dwProcessID就是进程号。
此问题由李海回答。
| |
|
|
| |
|
|