batch: Is there any function for converting %errorlevel% to HResult?

0

I want to get HResult from %errorlevel%. I tried to install a wrong product key using this command

wmic path SoftwareLicensingService WHERE (Version is not null) call InstallProductKey ProductKey='xyz'>nul 2>&1

The %errorlevel% now return -1073418160. Convert it to hex and add "0x" before it. I got 0xC004F050

I tried to use this command: powershell "\"0x{0:X}\" -F %errorlevel%. But I have chcp 65001 in the first line. Therefore, my console is not flat after running. Is there anyway to convert from %errorlevel% to HResult without executing Powershell? enter image description here

"Xin chào" is a traditional greeting of Vietnamese people

batch-file
asked on Stack Overflow Mar 25, 2020 by dphuc23

1 Answer

5

from DosTips:

call cmd /c exit /b -1073418160
echo %=exitcode%

Result:

C004F050

so you probably want:

call cmd /c exit /b %errorlevel%
echo 0x%=exitcode%
answered on Stack Overflow Mar 25, 2020 by Stephan

User contributions licensed under CC BY-SA 3.0