Windows批处理文件:最后一个进程的PID?
我正在从批处理文件启动浏览器。
START "www.google.com"
我想知道启动的这个浏览器窗口的PID。
一台机器上可以启动多个浏览器窗口。我需要找到仅由我的批处理文件启动的进程的 PID。我尝试使用 WINDOWTITLE 过滤器。但这不是一个好主意,因为未来标题可能会发生变化。我正在使用 Windows XP/7
任何帮助将不胜感激。 谢谢。
I am launching a browser from batch file.
START "www.google.com"
I would like to know the PID of this browser window launched.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对于它的价值(问题已经超过 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
这只是一个想法,为了让你可能
有一个名为 Tasklist 的命令,
有一个名为 filter /FI 的开关,可以让你决定要输出哪些过滤器参数,例如 PID。将其输出到 a > 1.TXT
启动您的流程,
重新检查监视列表并输出到 2.TXT
然后您就必须发挥创意。比较1和2,
也许从 2.TXT 中删除 1 中的进程
剩下的PID是你想要的吗?
This is just an idea, to get you maybe on the way
there is a command called Tasklist
there is a switch called filter /FI with lets you decide what filter parameters you want to output, f.e PID. Output this to a > 1.TXT
start your proces
recheck the watchlist and output to 2.TXT
Then you would have to get creative. COmpare 1 to 2,
maybe remove the processes in 1 from the 2.TXT
The remainig PID is what you wanted?
如果您有一定的编程经验,则可以创建自己的控制台应用程序,该应用程序接受命令行参数并将它们传递给 Win32 API
CreateProcess()
函数。其输出值之一是生成的进程 ID,您的应用程序随后可以返回该 ID。然后只需更新批处理文件即可调用您的应用,而不是直接使用START
。If you have some programming experience, you could create your own console application that accepts command-line parameters and passes them to the Win32 API
CreateProcess()
function. One of its output values is the spawned process ID, which your app could then return. Then just update your batch file to call your app instead of usingSTART
directly.我正在尝试做同样的事情。虽然一定有某种方法可以做到这一点,但我所有的谷歌搜索都表明没有。
请访问 robvanderwoude.com 查看第三方工具和示例的列表。另请在此处查看 Sysinternal 进程实用程序的完整列表。
I'm trying to do the same thing. Though there must be some way of doing it, but all my Googling suggests not.
Check out robvanderwoude.com to see a list of 3rd party tools and examples. Also check out the full list of Sysinternal's process utilities here.
我已经研究了大约 2 个小时,我认为有一种方法可以做到这一点,但它需要更多地了解 Windows 如何处理 PID 的 iexplore.exe...
我有一个批处理的工作版本我编写的文件将为您提供您想要的内容,但仅当它是第一个也是唯一一个打开的 Internet Explorer 窗口。
由于某种原因,当我打开新浏览器时,我无法更改 PID,但是如果没有打开窗口,我可以获得结果(显然是因为没有 PID)
无论如何,这就是我所拥有的......你应该是能够在您的系统上运行它,它会告诉您没有差异,如果您的默认浏览器是 Firefox 或 Chrome 或其他浏览器,它实际上可能会产生结果......只需对我提供的内容进行更改。
让我知道这是否有帮助...
I've been looking at this for about 2 hours now and I think that there is a way to do this, but it requires some more insight on how windows handles iexplore.exe for PID...
I have a working version of a batch file I wrote that will get you what you want, BUT only if its the FIRST AND ONLY Internet Explorer Window open.
For some reason I can't get the PID to change when I open new browsers, but I can get results if there is no window open (obviously because there is no PID)
Anyhow, this is what I have... you should be able to run this on your system and it will tell you that there are no differences and it might actually produce results if your default browser is Firefox or Chrome or something... just need to make the changes to what I'm providing.
Let me know if this helps...