bat 文件在 VirtualBox 中不起作用

bat file not working in VirtualBox

我的bat文件

@echo off
:loop
tasklist /fi "pid eq 788" | find ":" > nul
if errorlevel 1 (
  ping 127.0.0.1 -n 2
  goto loop
) else (
  goto continue
)
:continue
del "Run.exe"
ren latest.exe "Run.exe"
start "" "Run.exe" 
start /b " cmd /c del "%~f0"&exit /b

如果文件在主 PC 上执行 Windows 8.1 它工作正常没有任何错误但是如果我尝试 运行 它在 VirtualBox Windows XP 它不工作

遇到错误"no task running with the specified criteria"

知道为什么不能在 VM 中工作吗?

这是因为您没有运行使用 PID 788 执行任何任务。关于 PID 需要注意的一点是它们是随机分配的,同一个程序通常在每次 运行 时都有不同的 PID。
IE:第一次 运行 MyProgram.exe 它收到 1479 的 PID,第二次收到 1876 的 PID,依此类推。
编辑:系统程序除外,它们几乎总是在 1000 下具有 PID。 System Idle Process 的 PID 为 0System Interrupts 没有 PID (-)。