列出当前运行的进程:
var
PowerShellPath, ScriptPath, CommandLine: string;
begin
Memo6.Clear;
PowerShellPath := 'powershell.exe '; // 假设 PowerShell 可执行文件在系统环境变量中
// 构造命令行参数
CommandLine := 'Get-Process | Select-Object Name,Id';
// 设置命令行参数
DosCommand2.CommandLine := PowerShellPath + CommandLine;
// 启动进程
DosCommand2.Execute;
按照进程的id列出详细信息
var
PowerShellPath, ScriptPath, CommandLine: string;
begin
PowerShellPath := 'powershell.exe '; // 假设 PowerShell 可执行文件在系统环境变量中
// 构造命令行参数
CommandLine := ' Get-Process | Where-Object { $_.id -eq ' + #39 + self.Edit4.Text + #39 + '}';
// 设置命令行参数
DosCommand2.CommandLine := PowerShellPath + CommandLine;
// 启动进程
DosCommand2.Execute;
end;
按照进程的name列出详细信息
var
PowerShellPath, ScriptPath, CommandLine: string;
begin
PowerShellPath := 'powershell.exe '; // 假设 PowerShell 可执行文件在

该篇文章介绍了如何在Delphi程序中使用PowerShell脚本来管理和操作Windows进程,包括列出进程、按ID或名称筛选以及终止进程。展示了通过TStringList和StringGrid组件处理PowerShell命令输出的过程。
最低0.47元/天 解锁文章

1172





