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

查看:800
本文介绍了通过其进程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?

推荐答案

最基本的一种,要求任务列表过滤其输出并仅显示指示的进程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

note :在某些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天全站免登陆