O snippet de código a seguir pode levar à solução:
@ECHO OFF
SETLOCAL EnableExtensions
::: get my own process ID - use any method
::: applied here: altered TonyRoth's answer https://serverfault.com/a/126643/257436
set "_title=a885974x%random%"
title %_title%
for /f "tokens=2" %%G in ('tasklist /V ^| findstr "%_title%"') do (
set "_myProcessID=%%~G"
)
::: get the associated conhost process ID
set "_wQuery=ParentProcessId=%_myProcessID% and Name='conhost.exe'"
::: debug ::: wmic process where "%_wQuery%" get Name, ProcessId, WindowsVersion
for /f "usebackq" %%G in ('
wmic process where "%_wQuery%" get ProcessId^, WindowsVersion^|findstr /R "[0-9]"
') do set "_myConhostID=%%~G"
::: propagate results
set _my