I am trying to retrieve the Microsoft Office version using the following command:
reg query "HKEY_CLASSES_ROOT\Word.Application\CurVer"
this returns the following output:
HKEY_CLASSES_ROOT\Word.Application\CurVer
(Default) REG_SZ Word.Application.15
I need to parse the output and match the version using the following table and paste the final version into a text file.
Office 97 - 7.0
Office 98 - 8.0
Office 2000 - 9.0
Office XP - 10.0
Office 2003 - 11.0
Office 2007 - 12.0
Office 2010 - 14.0
Office 2013 - 15.0
Office 2016 - 16.0
How do i go about this?
I provided a similar answer in your previous, although seemingly ignored, question on Outlook.
There may be a way using the registry, (although only for Office 2007 onwards):
#Echo Off
If "%PROCESSOR_ARCHITECTURE:~-2%"=="86" (If Defined PROCESSOR_ARCHITEW6432 (
Set "KEY=\Wow6432Node" & Set "MWB=64") Else (Set "MWB=32" & Set "MOB=32"
)) Else Set "MWB=64"
Set "KEY=HKLM\Software%KEY%\Microsoft\Windows\CurrentVersion\Uninstall"
Set "GUID="
For /F "Delims=" %%A In ('Reg Query %KEY% /K /F "*-001B-*0FF1CE}"') Do (
If Not Defined GUID Set "GUID=%%~nxA")
If Not "%GUID:~-1%"=="}" Set "GUID="
If Not Defined GUID (Echo= Unable to find Office Product & GoTo EndIt)
If %GUID:~4,1% Equ 4 Set "IOV=10" Else (If %GUID:~4,1% Equ 2 (Set "IOV=07"
If Not Defined MOB Set "MOB=32") Else (If %GUID:~4,1% Equ 5 (Set "IOV=13"
) Else (If %GUID:~4,1% Equ 6 Set "IOV=16")))
If Not Defined IOV (Echo= Unknown Office version on your %MWB%-bit OS
GoTo EndIt)
If Not Defined MOB Set "MOB=32"
If %GUID:~20,1% Equ 1 Set "MOB=64"
Echo=&Echo= Office 20%IOV% %MOB%-bit Product installed on a %MWB%-bit OS
:EndIt
Timeout 5 1>Nul
This has not been tested because I have never been able to justify the cost of any Microsoft Office product.
#echo off
for /f "tokens=5* skip=1 delims=. " %%a in ('reg query "HKEY_CLASSES_ROOT\Word.Application\CurVer"') do set "wver=%%a.0"
for %%# in ("Office 97-7.0" "Office 98-8.0" "Office 2000-9.0" "Office XP-10.0" "Office 2003-11.0" "Office 2007-12.0" "Office 2010-14.0" "Office 2013-15.0" "Office 2016-16.0") do (
for /f "tokens=1* delims=-" %%a in ("%%~#") do (
if %%b equ %wver% (
set ov=%%a
)
)
)
echo %ov%
But you have pretty old versions of the MS Office which can be installed only on windows xp (or even older versions of windows) where the reg command is not available. So you can also check this which uses FTYPE command to determine the office version
Related
I am looking for a batch that will allow me to run or not depending on the edition of Windows. It will run on all editions of Windows 10 except Home (or Core) and S. For the moment I have successfully filtered according to the build but it is not enough.
I also looked at the registry key EditionID in : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion and wmic os get caption but being a beginner in batch I can't integrate it in my .bat
FOR /f "tokens=6 delims=[]. " %%i in ('ver') do SET build=%%i
IF %build% LSS 17763 (
COLOR E
ECHO.===============================================================================
ECHO. ALERT - Not compatible with previous versions ... the RS5
ECHO.===============================================================================
ECHO.
PAUSE
GOTO :EOF
)
You could just use this at the beginning of your batch file:
#Echo Off
SetLocal EnableExtensions
Set /A "SKU=OSV=0"
For /F "EOL=O Tokens=1,2 Delims=. " %%G In ('%SystemRoot%\System32\wbem\WMIC.exe
OS Where "Version>10" Get OperatingSystemSKU^, Version 2^>NUL'
) Do Set /A "SKU=%%G, OSV=%%H" 2>NUL
If Not %OSV% Equ 10 GoTo :EOF
For %%G In (98 99 100 101 123 125 126 129 130 131) Do If %%G Equ %SKU% GoTo :EOF
Rem Your code goes here
The idea is to end the script if the detected OS is not Windows 10, and if the Windows 10 Edition is any one of the following:
Edition Identifier
SKU
Operating System Definition
CoreN
98
Windows 10 Home N
CoreCountrySpecific
99
Windows 10 Home China
CoreSingleLanguage
100
Windows 10 Home single language
Core
101
Windows 10 Home
IoTUAP
123
Windows 10 IoT Core
EnterpriseS
125
Windows 10 Enterprise LTSB
EnterpriseSN
126
Windows 10 Enterprise LTSB N
EnterpriseSEval
129
Windows 10 Enterprise LTSB Evaluation
EnterpriseSNEval
130
Windows 10 Enterprise LTSB N Evaluation
IoTUAPCommercial
131
Windows 10 IoT Core Commercial
You can obviously add or remove SKU's within the parentheses on line 8 as required.
Based on this post for changing the output color of command prompt text in Windows 10, I'm looking for the best way to detect the OS version in a batch file IF statement.
How to echo with different colors in the Windows command line
From my understanding, colorized text was added in Windows 10 Threshold 2 November 18, 2015 (10.0.10586.11)
In Windows 10 version history, up until the Version 1607 (Anniversary Update), there was a major.minor.build.revision numbering scheme so I want the detection to be very granular.
https://en.wikipedia.org/wiki/Windows_10_version_history
I found this post which compares major.minor.build to a user input, but can't wrap my head around what it's doing for my needs.
https://github.com/LogicDaemon/PersonalUseScripts/blob/c3346df9c7c0f57b584b5c0238b8e8b76096c42c/cmd/superuser%20q%20891742/CheckWinVer.cmd
So based on that information, I'm trying to compare the detected version of windows to 10.0.10586.11 in a batch file.
If its greater than or equal to that version, colorize the text, if not use standard formatting.
This was my first attempt to colorize text in an IF statement. Although this appeared to work in Windows 10, it didn't work in Windows 8.1 because string "10." is less than "6.3"
FOR /F "tokens=4-5 delims=. " %%i in ('ver') DO SET Version=%%i.%%j
IF "%Version%" GEQ "10.0" (echo [92mHere is my text in green.[0m) ELSE (echo Here is my text)
Note the required escape characters are missing in the above sample
Compare numeric values instead of strings (e.g. Windows 8.1 returns 603):
FOR /F "tokens=4-5 delims=. " %%i in ('ver') DO SET /A _Version=%%i*100+%%j
IF %_Version% GEQ 1000 (echo [92mHere is my text in green.[0m) ELSE (echo Here is my text)
Edit. Instead of wikipedia, I'd use a primary source Windows 10 release information on Microsoft’s TechNet site.
FOR /F "tokens=4-7 delims=[]. " %%i in ('ver') DO (
SET /A _MajorMinor = %%i * 100 + %%j
set /A _Build = %%k0 /10
set /A _Revision = %%l0 /10
)
set "_AE=" AE like Ansi Escape
IF %_MajorMinor% GEQ 1000 if %_Build% GTR 10586 ( set "_AE=Yes" ) else (
if %_Build% EQU 10586 if %_Revision% GEQ 11 set "_AE=Yes" )
rem use the _AE flag
if defined _AE (echo [92mHere is my text in green.[0m) ELSE (echo Here is my text)
Used nested IFs (effective as of logical AND).
The set /A _Revision = %%l0 /10 construct used to avoid Missing operator on Windows 8 where the 7th token %%l results to an empty string.
As our office upgrades to Window 7, I have been tasked to update the loginscript to work with Windows 7. The creators of said script are long gone, and I am not a batch file expert.
What I am trying to do is determine the OS. As I do some network administration duties, I need to be able to log on to a server without running the login script whereas I will need to the login script to run if I log into a Windows XP or Windows 7 computer.
I found I couldn't use the VER command as Windows 7 and Windows Server 2008 return the exact same results.
This is what I have:
if exist %loginscriptdir%\sysinfo.txt goto setver
if not exist %loginscriptdir%\sysinfo.txt wmic os get name /value > %loginscriptdir%\sysinfo.txt
type %loginscriptdir%\sysinfo.txt > %loginscriptdir%\sysinfo1.txt
:setver
set WinVer=Unknown
set errorlevel=0
If %WinVer% == "Unknown" (
findstr /c:"Windows XP Professional" %loginscriptdir%\sysinfo1.txt
if %errorlevel%==1 set WinVer=XP
) else (
findstr /c:"Windows 7 Enterprise" %loginscriptdir%\sysinfo1.txt
if %errorlevel%==1 set WinVer=Win7
)
set result=false
if %WinVer% == "XP" set result=true
if %WinVer% == "Win7" set result=true
if "%result%" == "false" (
goto skipicon1
Throughout the script, I wrote in breaks to find the values. Example:
REM -----
ECHO "%WinVer%"
ECHO "%result%"
ECHO "%errorlevel%"
ECHO Press any key to continue 4.
pause>null
REM -----
The fourth break comes at the end of the script I pasted above. These are the results:
"Unknown"
"false"
"0"
Press any key to continue 4.
Here you go. This is the best way I've found to get the OS accurately from win2kpro-winserver2k10. It also tells if it's 32/64 bit and what sp is installed but you don't have to. Just check %cap% in this example.
#echo off
setlocal
call :GetOS cap bit sp
echo %cap%%bit% (%sp%)
exit /b
:GetOS caption servicepack
setlocal
set arc=%PROCESSOR_ARCHITECTURE%
set key="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
for /f "tokens=3*" %%a in (
'reg query %key%^|findstr /i ProductName') do set cap=%%a %%b
for /f "tokens=3*" %%a in (
'reg query %key%^|findstr /i CSDVersion') do set sp=%%a %%b
endlocal & set %1=%cap% & set %2=%arc% & set %3=%sp%
exit /b
The issue with the code is the expansion of the %errorlevel% value. Since it is contained within a scope of parentheses, the value will not be updated till after the scope ends. Meaning that %errorlevel% will always equal its value when the scope began. To fix this you would have to use delayed expansion. setlocal enabledelayedexpansion and !errorlevel!. Here is a StackOverflow post about delayed expansion: Enable and Disable Delayed Expansion, what does it do?
You may just want to use the version detection method shown at ss64.com http://ss64.com/nt/ver.html
Here is the example from ss64.com but simplified:
#echo off
setlocal
:: Get windows Version
for /f "tokens=4,5,6 delims=[.] " %%A in ('ver') do (
set "Major=%%~A"
set "Minor=%%~B"
set "Build=%%~C"
)
if "%Major%.%Minor%"=="5.1" goto WinXP
if "%Major%.%Minor%"=="6.1" goto Win7
echo Unsupported Version Detected "%Major%.%Minor%"
goto End
:WinXP
echo Windows XP Detected
goto End
:Win7
echo Windows 7 or Server 2008 Detected
goto End
:End
endlocal
exit /b 0
I have a (test) batch file with this code
If Exist "C:\Users\All Users\ntuser.dat" Goto Win 7
If Exist "C:\Documents and Settings\All Users\ntuser.dat" Goto Win XP
:Win 7
will write here the parameters which'll run on win7
C:\w7\test.txt
:Win XP
will write here the parameters which'll run on winxp
and so the same with other os + os architecture
it's working, but i need to add more os identify options..
I need that batch file to identify os version, architecture (Windows 2003R2 x64 only, Windows Xp x32 and x64, Windows Vista x32 and x64, Windows 7 x32 and x64, Windows 8 x32 and x64)
Thank you very much in Advanced!
there is a nice solution from Aacini here on SO, but can't find it now and post it from my "library":
#echo off
setlocal EnableDelayedExpansion
::Identify OS
for /F "delims=" %%a in ('ver') do set ver=%%a
set Version=
for %%a in (95=95 98=98 ME=ME NT=NT 2000=2000 5.1.=XP 5.2.=2003 6.0.=Vista 6.1.=7 6.2.=8) do (
if "!Version!" equ "this" (
set Version=Windows %%a
) else if "!ver: %%a=!" neq "%ver%" (
set Version=this
)
)
::Identify bit
if exist "%SYSTEMDRIVE%\Program Files (x86)" (
set Type=64 bit
) else (
set Type=32 bit
)
::Display result
echo %Version% %Type%
goto :eof
::Goto right version
goto %Version: =_%
:Windows_8
echo Windows 8
:Windows_7
echo Windows 7
© Aacini at dostips
Just use WMIC from command line or batch file. Much easier, shorter and you can parse it.
wmic OS get OSArchitecture,caption
I'm programming for an embedded device with a NVIDIA Tegra 2 running Windows Embedded Compact 7. My development environment is Microsoft Visual Studio 2008. The boost library and especially the boost-asio package seems to be very helpfull for my needs. Unfortunately I was not able to find a good guide on how to get boost running on Windows Embedded Compact 7. I'd prefere to get .lib files which I can link statically into my application.
It appears that the documentation on this process is sparse, because it requires non-trivial updates to the build process to get working with Windows CE. The most comprehensive tutorial to this problem appears to be here.
Since you explicitly tagged this boost-asio, I also looked into that component of Boost specifically. Here's a thread from the Boost mailing list that covers this library in detail, including potential failure cases you may experience, JAM file modifications, and a batch file to help you with the build.*
For those reading this: please share your experiences once you get this working. Despite various concerns that Boost is too memory-heavy for embedded applications, Boost provides the ability to use separate packages to meet your needs. I expect other users on SO will be very interested in your experiences getting this working.
* Because people have been expressing problems with the referenced batch file disappearing when Nabble links expire, here's a pastedump for posterity:
#SET VCINSTALLDIR=%VS9INSTALLDIR%\VC
#if "%VS9INSTALLDIR%"=="" goto error_no_VSINSTALLDIR
#if "%VCINSTALLDIR%"=="" goto error_no_VCINSTALLDIR
#echo Setting environment for using Microsoft Visual Studio 2008 tools for WM5.
#set TARGETCPU=X86
#call :GetWindowsSdkDir
#if not "%WindowsSdkDir%" == "" (
set "PATH=%WindowsSdkDir%bin;%PATH%"
)
#rem
#rem Root of Visual Studio IDE installed files.
#rem
#set DevEnvDir=%VS9INSTALLDIR%\Common7\IDE
#set PATH=%VCINSTALLDIR%\CE\bin\x86_arm;%VCINSTALLDIR%\bin;%VS9INSTALLDIR%\Common7\Tools;%DevEnvDir%;%VS9INSTALLDIR%\Common\Tools;%VS9INSTALLDIR%\Common\IDE;%VS9INSTALLDIR%;%PATH%
#set INCLUDE=%STLPORT_PATH%\STLPort-5.2.1\stlport;%VCINSTALLDIR%\ce\include;%CETOOLS%\Windows Mobile 5.0 Pocket PC SDK\include\ARMV4I;%CETOOLS%\Windows Mobile 5.0 Pocket PC SDK\include;%VCINSTALLDIR%\ce\atlmfc\include
#set LIB=%STLPORT_PATH%\STLPort-5.2.1\lib\evc9-arm;%CETOOLS%\Windows Mobile 5.0 Pocket PC SDK\lib\ARMV4I;%VCINSTALLDIR%\ce\ATLMFC\LIB\ARMV4I;%VCINSTALLDIR%\ce\LIB\ARMV4I
#set LIBPATH=
#goto end
:GetWindowsSdkDir
#call :GetWindowsSdkDirHelper HKLM > nul 2>&1
#if errorlevel 1 call :GetWindowsSdkDirHelper HKCU > nul 2>&1
#if errorlevel 1 set WindowsSdkDir=%VCINSTALLDIR%\PlatformSDK\
#exit /B 0
:GetWindowsSdkDirHelper
#for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows" /v "CurrentInstallFolder"') DO (
if "%%i"=="CurrentInstallFolder" (
SET "WindowsSdkDir=%%k"
)
)
#if "%WindowsSdkDir%"=="" exit /B 1
#exit /B 0
:error_no_VSINSTALLDIR
#echo ERROR: VS9INSTALLDIR variable is not set.
#goto end
:error_no_VCINSTALLDIR
#echo ERROR: VCINSTALLDIR variable is not set.
#goto end
:end
#SET VCINSTALLDIR=%VS9INSTALLDIR%\VC
#SET FrameworkDir=C:\WINDOWS\Microsoft.NET\Framework
#SET FrameworkVersion=v2.0.50727
#SET Framework35Version=v3.5
#if "%VS9INSTALLDIR%"=="" goto error_no_VSINSTALLDIR
#if "%VCINSTALLDIR%"=="" goto error_no_VCINSTALLDIR
#echo Setting environment for using Microsoft Visual Studio 2008 x86 tools with STLport-5.2.1.
#call :GetWindowsSdkDir
#if not "%WindowsSdkDir%" == "" (
set "PATH=%WindowsSdkDir%bin;%PATH%"
set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%"
set "LIB=%WindowsSdkDir%lib;%LIB%"
)
#rem
#rem Root of Visual Studio IDE installed files.
#rem
#set DevEnvDir=%VS9INSTALLDIR%\Common7\IDE
#set PATH=%DevEnvDir%;%VCINSTALLDIR%\BIN;%VS9INSTALLDIR%\Common7\Tools;%FrameworkDir%\%Framework35Version%;%FrameworkDir%\%FrameworkVersion%;%VCINSTALLDIR%\VCPackages;%PATH%
#set INCLUDE=%STLPORT_PATH%\STLport-5.2.1\stlport;%VCINSTALLDIR%\ATLMFC\INCLUDE;%VCINSTALLDIR%\INCLUDE;%INCLUDE%
#set LIB=%STLPORT_PATH%\STLport-5.2.1\lib\vc9;%VCINSTALLDIR%\ATLMFC\LIB;%VCINSTALLDIR%\LIB;%LIB%
#set LIBPATH=%FrameworkDir%\%Framework35Version%;%FrameworkDir%\%FrameworkVersion%;%VCINSTALLDIR%\ATLMFC\LIB;%VCINSTALLDIR%\LIB;%LIBPATH%
#goto end
:GetWindowsSdkDir
#call :GetWindowsSdkDirHelper HKLM > nul 2>&1
#if errorlevel 1 call :GetWindowsSdkDirHelper HKCU > nul 2>&1
#if errorlevel 1 set WindowsSdkDir=%VCINSTALLDIR%\PlatformSDK\
#exit /B 0
:GetWindowsSdkDirHelper
#for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows" /v "CurrentInstallFolder"') DO (
if "%%i"=="CurrentInstallFolder" (
SET "WindowsSdkDir=%%k"
)
)
#if "%WindowsSdkDir%"=="" exit /B 1
#exit /B 0
:error_no_VSINSTALLDIR
#echo ERROR: VSINSTALLDIR variable is not set.
#goto end
:error_no_VCINSTALLDIR
#echo ERROR: VCINSTALLDIR variable is not set.
#goto end
:end