Windows批处理命令来确定一个进程的工作目录 [英] windows batch command to determine working directory of a process

查看:473
本文介绍了Windows批处理命令来确定一个进程的工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我问的是,我的程序使用第三方软件,有时留下一些没有链接回我的程序或第三方程序孤立进程。这些孤儿的进程开始随着时间的推移加起来,消耗吨资源。我想杀死他们定期,但为了我这样做,我需要确切知道他们被我的程序创建的,而不是其他一些程序。我已经看到了孤儿进程的Process Explorer,看着进程的属性时,我看到一个名为当前目录字段中。为孤立进程的当前目录是我的程序的安装目录。这会给我安慰我杀死我的程序创建的过程。

Why I ask is that my program uses 3rd party software that sometimes leaves behind orphan processes that have no link back to my program or the 3rd party process. These orphan processes start to add up and consume tons of resources over time. I would like to kill them off periodically, but in order for me to do that, I need to know for sure they were created by my program and not some other program. I have viewed the orphan processes in Process Explorer and when looking at the properties of the process, I see a field called "Current Directory". The current directory for the orphaned process is the install directory of my program. This would give me reassurance I am killing a process created by my program.

由于这些过程是由第三方创建的,我需要的只是杀了他们,他们是由他们或东西运行的taskkill创建后。有没有办法找出使用开箱窗口命令批处理文件进程的当前工作目录?如果这可以通过查询WMIC这将是preferable做到的,但我似乎无法使用WMIC时,发现当前的工作目录。我认为,如果进程资源管理器能够获得这个信息,我应该可以通过一些批处理命令得到它了。

Since these processes are created by a 3rd party, I need to just kill them after they are created by running taskkill on them or something. Is there a way to figure out the current working directory of a process using out of the box windows commands in a batch file? If this can be done through wmic queries that would be preferable, but I cannot seem to find the current working directory when using wmic. I assume if Process Explorer is able to obtain this info, I should be able to get it too through some batch commands.

推荐答案

TLIST WDK 救援!它的输出(CWD:...)的第二行显示了一个进程的工作目录:

tlist from WDK to the rescue! The 2nd line of its output ("CWD: ...") shows the working directory of a process:

> tlist 944
 944 postgres.exe
   CWD:     D:\Lab\Database\pgsql\test\
   CmdLine: "D:/Tools/pgsql/bin/postgres.exe"  -D "."
   VirtualSize:   221116 KB   PeakVirtualSize:   242620 KB
   WorkingSetSize: 17076 KB   PeakWorkingSetSize: 19336 KB
   NumberOfThreads: 4
   9084 Win32StartAddr:0x00000000 LastErr:0x00000000 State:Waiting
   8504 Win32StartAddr:0x00000000 LastErr:0x000000b7 State:Waiting
   8616 Win32StartAddr:0x00000000 LastErr:0x00000000 State:Waiting
   7468 Win32StartAddr:0x00000000 LastErr:0x00000000 State:Waiting
    9.3.5.14202 shp  0x0000000000400000  D:\Tools\pgsql\bin\postgres.exe
 6.1.7601.18247 shp  0x00000000770D0000  C:\Windows\SYSTEM32\ntdll.dll
 ...

请参阅的文档获得更多信息。

这篇关于Windows批处理命令来确定一个进程的工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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