Board logo

标题: [系统相关] 批处理如何获取进程的映像路径? [打印本页]

作者: Wingl83    时间: 2010-9-28 13:57     标题: 批处理如何获取进程的映像路径?

如图,则显示
  1. c:\wing\a.bat
复制代码

作者: cjiabing    时间: 2010-9-28 17:51

用WMIC:
  1. @echo off&setlocal enabledelayedexpansion
  2. ::获取单个名称进程的PID
  3. for /f "usebackq skip=1 delims=" %%p in (`"wmic process where(name="QQ.exe") get ProcessId"`) do echo %%p
  4. ::获取单个名称进程的路径
  5. for /f "usebackq skip=1 delims=" %%p in (`"wmic process where(name="QQ.exe") get executablepath"`) do echo %%p
  6. ::查找单个名称进程的PID
  7. for /f "tokens=*" %%i in ('tasklist') do echo %%i |findstr /i "cmd"
  8. pause
复制代码

作者: Wingl83    时间: 2010-9-28 17:55

2楼没有明白我的意思,如1楼的图,并非要获取C:\WINDOWS\system32\cmd.exe,而是要获取c:\wing\a.bat
作者: cjiabing    时间: 2010-9-28 18:04     标题: 回复 3楼 的帖子

说实在的,我都不怎么懂映像路径和命令行的实际作用,不过通过以下提取你或许会有答案:
  1. wmic process where(name="cmd.exe")
复制代码
前提是你先随机运行一个批处理作品,如:E:\Batch\获取桌面快捷方式的路径.bat
然后你通过上面查找映像路径,通过FOR或者FINDSTR提取……
我是对比任务管理器来理解的。
作者: cjiabing    时间: 2010-9-28 18:08

不懂“映像路径”的英文,你自己找吧,吃饭去了:
wmic process get  /?
========
CSName
CommandLine
Description
ExecutablePath
ExecutionState
Handle
HandleCount
InstallDate
KernelModeTime
MaximumWorkingSetSize
MinimumWorkingSetSize
Name
OSName
OtherOperationCount
OtherTransferCount
PageFaults
PageFileUsage
ParentProcessId
PeakPageFileUsage
PeakVirtualSize
PeakWorkingSetSize
Priority
PrivatePageCount
ProcessId
QuotaNonPagedPoolUsage
QuotaPagedPoolUsage
QuotaPeakNonPagedPoolUsage
QuotaPeakPagedPoolUsage
ReadOperationCount
ReadTransferCount
SessionId
Status
TerminationDate
ThreadCount
UserModeTime
VirtualSize
WindowsVersion
WorkingSetSize
WriteOperationCount
WriteTransferCount
作者: lxzzr    时间: 2010-9-28 18:30

那是获取命令行参数

wmic process get commandLine
作者: SunTB    时间: 2012-2-7 15:32

土办法,等人完善
  1. @echo off
  2. set file=c:\wing\a.bat
  3. wmic process get commandLine,processid >t.txt
  4. for /f "delims=" %%a in ('type t.txt^|find /i "%file%"') do set pth=%%a
  5. set pth2=%pth:""=[%
  6. for /f "tokens=2 delims=[]" %%i in ('echo "%pth2:" "=]%"') do set pth=%%i
  7. echo.%pth%
  8. del /f/q t.txt
  9. echo.&pause
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2