@ECHO OFF
SETLOCAL
SET "DESC="
FOR /f "tokens=1*delims=: " %%a IN ('sc qdescription "bonjour service" ') DO (
IF "%%a"=="DESCRIPTION" SET "desc=%%b"
)
ECHO DESC=%DESC%
:: Setting DESC to the string expected - then ECHOing to prove
SET "DESC=C:\Program Files (x86)\TEST\small.exe /service"
ECHO DESC=%DESC%
:: Now remove part past '/' and select drive/path from assumed filename
FOR /f "tokens=1delims=/" %%a IN ("%desc%") DO SET "desc=%%~dpa"
ECHO DESC=%DESC%
:: Now remove terminal "\"
SET "desc=%desc:~0,-1%"
ECHO DESC=%DESC%
:: Extension - to remove the last "leaf" directoryname
::
FOR /f "delims=" %%a IN ("%desc%") DO SET "desc=%%~dpa"
ECHO DESC=%DESC%
:: Now remove new terminal "\"
SET "desc=%desc:~0,-1%"
ECHO DESC=%DESC%
GOTO :EOF
You'd need to save this text in a file named whateveryoulike.bat then run it as whateveryoulike from the command-prompt.
I used an installed service on my machine since I don't have access to yours. You would need to substitute your servicename in place of bonjour service above.
I then set desc to the value you show you are getting, and then how to process it down to the portion you require.
Modified to remove the last directoryname leaf.