windows(7)如何获取可执行位置(来自任务管理器)?

时间:2017-12-03 19:50:44

标签: windows cmd virtualbox batch-processing wmic

我在其中一个硬盘驱动器(Portable Virtual Box)上设置了Portable VirtualBox。我在我的系统中安装了另一个VirtualBox(这个不是可移植的,但在C:\ Program Files中经典安装)

我试图使用BATCH脚本来检索正在运行的VirtualBox的位置:

@echo off
cls
setlocal enabledelayedexpansion

ECHO Please make sure you have VirtualBox running, so the script
ECHO will be able to detect VirtualBox.exe process running

rem because of a bug in wmic, I have to get the Input Locale first.
rem I could have had it hardcoded, but I think this is better (more flexible)
for /f "tokens=2 delims=:,;" %%s in ('systeminfo ^| find /i "Input Locale:"') DO (
SET locale=%%~ns
set locale=!locale: =!
)

rem this is the actual search for the executable location
FOR /f "tokens=2 delims=," %%I IN ('wmic process where "name='virtualbox.exe'" get ExecutablePath^,Handle /Format:"%WINDIR%/System32/wbem/!locale!/csv" ^| FIND /i "virtualbox.exe"') DO SET "exepath=%%~I"
ECHO Detected Path: !exepath!

endlocal

但我总是得到

  

" C:\ Program Files \ Oracle \ VirtualBox \ VirtualBox.exe"。

我尝试从任务管理器(右键单击>打开文件位置),无论运行哪个VirtualBox实例,它都会发生相同的情况。 在我的" C:\ Program Files"中卸载版本能够正确检测便携式设备。

是否有任何方式(使用BATCH)正确检测正在运行的进程可执行位置(在我的情况下是VirtualBox.exe),当情况与上述情况类似时(运行已安装程序的可移植版本)?

0 个答案:

没有答案