Sha*_*ala 1 delphi process delphi-xe2
我正在使用这个名为TProcessInfo的非可视化开源组件来获取进程列表,ProcessID以及我放入ListView的完整路径.
我用来执行此操作的代码:
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
Process: TProcessItem;
begin
for i := 0 to ProcessInfo1.RunningProcesses.Count -1 do
begin
Process := ProcessInfo1.RunningProcesses[i];
with lv.Items.Add do
begin
Caption := Process.ExeFile;
SubItems.Add(IntToStr(Process.ProcessID));
SubItems.Add(Process.FullPath);
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
代码将始终在最后一行中断:SubItems.Add(Process.FullPath);我收到一条错误消息:
系统错误.代码:87
参数不正确.
在Component中获取FullPath的代码是:
function TProcessItem.GetFullPath: TFileName;
var
hProcess: THandle;
begin
hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,False,FProcessID);
if hProcess <> 0 then
begin
try
SetLength(Result,MAX_PATH);
FillChar(Result[1],Length(Result) * SizeOf(Char), 0);
if GetModuleFileNameEx(hProcess,0,PChar(Result),Length(Result)) > 0 then
Result := Trim(Result)
else
RaiseLastOSError;
finally
CloseHandle(hProcess)
end;
end
else
RaiseLastOSError;
end;
Run Code Online (Sandbox Code Playgroud)
如果像错误状态 - 参数不正确,那么我该如何更改?
**组件使用PsAPI,我在Windows 7上使用Delphi XE2 Ultimate x64也发生在Windows XP Pro x86上