通过进程 ID 查找进程名称 [英] Find Process Name by its Process ID

查看:36
本文介绍了通过进程 ID 查找进程名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我知道进程 ID.我想使用 Windows 批处理脚本通过其 ID 查找进程名称.我该怎么做?

Suppose I know the process ID. I want to find the process name by its ID, using windows batch script. How can I do this?

推荐答案

基本的,让tasklist过滤它的输出,只显示指定的进程id信息

The basic one, ask tasklist to filter its output and only show the indicated process id information

tasklist /fi "pid eq 4444" 

只获取进程名,必须拆分行

To only get the process name, the line must be splitted

for /f "delims=," %%a in ('
    tasklist /fi "pid eq 4444" /nh /fo:csv
') do echo %%~a

在这种情况下,以 csv 格式 (/fo:csv) 检索不带标题 (/nh) 的进程列表.逗号用作标记分隔符,行中的第一个标记是图像名称

In this case, the list of processes is retrieved without headers (/nh) in csv format (/fo:csv). The commas are used as token delimiters and the first token in the line is the image name

注意:在某些 windows 版本中(其中一个,我的例子,是西班牙 windows xp 版本),任务列表中的 pid 过滤器不起作用.在这种情况下,必须在命令之外完成对进程列表的过滤

note: In some windows versions (one of them, my case, is the spanish windows xp version), the pid filter in the tasklist does not work. In this case, the filter over the list of processes must be done out of the command

for /f "delims=," %%a in ('
    tasklist /fo:csv /nh ^| findstr /b /r /c:"[^,]*,"4444","
') do echo %%~a

这将生成任务列表并过滤它,在 csv 输出的第二列中搜索进程 ID.

This will generate the task list and filter it searching for the process id in the second column of the csv output.

已编辑:或者,您可以假设将操作系统翻译成西班牙语的团队做了什么.我不知道在其他地区会发生什么.

edited: alternatively, you can suppose what has been made by the team that translated the OS to spanish. I don't know what can happen in other locales.

tasklist /fi "idp eq 4444" 

这篇关于通过进程 ID 查找进程名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆