0

I have a script that works perfectly.

 if not exist %SystemRoot%\system32\systeminfo.exe goto warnthenexit

 systeminfo | find "OS Name" > osname.txt

 FOR /F "usebackq delims=: tokens=2" %%i IN (osname.txt) DO set vers=%%i

 echo %vers% | find "Windows 7" > nul

 if %ERRORLEVEL% == 0 goto VERSION_7

However, when I try to print the results like so:

Echo Current OS:%vers% - 64 Bit

It prints the results with a really! long gap. Like so:

Current OS:                   Microsoft Windows 7 Enterprise  - 64 Bit

Does anyone know why? or how I can remove the large gap?

Thanks a million!

2

2 Answers 2

1

I know your script "works perfectly", but is not much efficient.

SYSTEMINFO takes a lot of time and osname.txt may be avoided.

Check:

FOR /F "TOKENS=1,* DELIMS==" %%u IN ('WMIC OS GET CAPTION /VALUE') DO IF /I "%%u"=="Caption" SET vers=%%v
Sign up to request clarification or add additional context in comments.

1 Comment

What is more, systeminfo output is localized, including "OS Name" label itself being replaced by translation (so findstr "OS Name" will not work in non-English Windows). wmic's output, on the other hand, is not localized, so one can findstr all the way they want :-)
0

Changed

FOR /F "usebackq delims=: tokens=2" %%i IN (osname.txt) DO set vers=%%i

To

FOR /F "usebackq delims=  tokens=2" %%i IN (osname.txt) DO set vers=%%i

*Changed the : to a %space% after delims...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.