Windows批处理文件:上一个进程的PID? [英] Windows batch file : PID of last process?

查看:85
本文介绍了Windows批处理文件:上一个进程的PID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从批处理文件启动浏览器.

I am launching a browser from batch file.

START "www.google.com"

我想知道此浏览器窗口的PID已启动.

I would like to know the PID of this browser window launched.

在一台计算机上可以启动许多浏览器窗口.我只需要查找由批处理文件启动的进程的PID.我尝试使用WINDOWTITLE过滤器.但这不是一个好主意,因为标题将来可能会更改.我正在使用Windows XP/7

There can be many browser windows launched on a single machine. I need to find the PID of the process which was launched by my batch file only. I tried with WINDOWTITLE filter. But its not a good idea as titles may change in future. I am using Windows XP/7

任何帮助将不胜感激. 谢谢.

Any help would be appreciated. Thanks.

推荐答案

对于该代码(问题已经存在2年以上)了,此代码可以解决问题,只需根据默认浏览器exe更改变量即可.

For what it worth (question is more than 2 years old) this code do the trick, just change variable according to default browser exe

set "browser=palemoon.exe"

tasklist /FI "imagename eq %browser%" /NH /FO csv > task-before.txt
start www.google.com
tasklist /FI "imagename eq %browser%" /NH /FO csv > task-after.txt

:: fc /L /LB1  test4-Before.txt test4-After.txt | find /I "%browser%"
for /f "delims=, tokens=2,*" %%A in ('"fc /L /LB1  task-before.txt task-after.txt | find /I "%browser%""') do set pid=%%A

SETLOCAL enabledelayedexpansion
pid=!pid:"=!
ENDLOCAL
echo pid is %pid%

这篇关于Windows批处理文件:上一个进程的PID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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