I'm going to make a Windows batch file with a variable called %ProductKey%. I have the code which determines the version of Windows(Which is the variable %WINVER%). It should set the ProductKey variable with if command and echo %ProductKey%, which should be XXXXX-XXXXX-XXXXX-XXXXX-XXXXX.
for /f "usebackq skip=1 tokens=*" %%i in (`WMIC OS Get Caption ^| findstr /r /v "^$"`) do set WINVER=%%i
if "%WINVER%" == "Microsoft Windows 10 Pro" ( set ProductKey=XXXXX-XXXXX-XXXXX-XXXXX-XXXXX )
echo %ProductKey%
pause
%WINVER% is Microsoft Windows 10 Pro for my PC.
It should display me XXXXX-XXXXX-XXXXX-XXXXX-XXXXX which is the product key, it shows me just echo is off.
I'd suggest you add a line
echo "%WINVER%"
before the "if" test.
With Windows 10 Home, this shows "Microsoft Windows 10 Home " . I can't test with Windows 10 Pro, but my intuition tells me that Pro will also show those trailing spaces.
Perhaps
if "%WINVER: =%" == "MicrosoftWindows10Pro" ...
will cure your problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.