You are not logged in.

#1 08 Jun 2016 14:48

Eehixohw
Member
Registered: 25 Sep 2011
Posts: 40

Check MS Office Version in Registry

I have the following batch snippet:

SET oVer=15.0
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location99" /v AllowSubFolders /d 00000001 /t REG_DWORD /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location99" /v Path /d "C:\\" /t REG_SZ /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location98" /v AllowSubFolders /d 00000001 /t REG_DWORD /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location98" /v Path /d "C:\Users" /t REG_SZ /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location97" /v AllowSubFolders /d 00000001 /t REG_DWORD /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location97" /v Path /d "D:\\" /t REG_SZ /f

The idea of the script is to create these keys based on the version variable above. Office 2010 is 14.0, Office 2013 is 15.0 and 2016 is 16.0. I'd like a code that will search through the base key HKEY_CURRENT_USER\Software\Microsoft\Office\ for this number version and set the number to the oVer variable above.

Thank you!

Offline

#2 08 Jun 2016 22:38

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: Check MS Office Version in Registry

You might find you have multiple versions.  This code should enumerate them for you:

for /f "usebackq tokens=*" %%a in (`reg query HKEY_CURRENT_USER\Software\Microsoft\Office ^| find "."`) do echo:%%~nxa

For me, this displays 5 different Office versions.  You could add your data for all versions with something like this (untested):

@echo off
for /f "usebackq tokens=*" %%a in (`reg query HKEY_CURRENT_USER\Software\Microsoft\Office ^| find "."`) do call :add_keys %%~nxa

goto :EOF

:add_keys

SET oVer="%~1"
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location99" /v AllowSubFolders /d 00000001 /t REG_DWORD /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location99" /v Path /d "C:\\" /t REG_SZ /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location98" /v AllowSubFolders /d 00000001 /t REG_DWORD /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location98" /v Path /d "C:\Users" /t REG_SZ /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location97" /v AllowSubFolders /d 00000001 /t REG_DWORD /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location97" /v Path /d "D:\\" /t REG_SZ /f
goto :EOF

Last edited by bluesxman (08 Jun 2016 22:40)


cmd | *sh | ruby | chef

Offline

#3 09 Jun 2016 10:36

Eehixohw
Member
Registered: 25 Sep 2011
Posts: 40

Re: Check MS Office Version in Registry

Thank you so much! It works with a minor adjustment:
SET oVer=%~1

@echo off
for /f "usebackq tokens=*" %%a in (`reg query HKEY_CURRENT_USER\Software\Microsoft\Office ^| find "."`) do call :add_keys %%~nxa

goto :EOF

:add_keys

SET oVer=%~1
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location99" /v AllowSubFolders /d 00000001 /t REG_DWORD /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location99" /v Path /d "C:\\" /t REG_SZ /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location98" /v AllowSubFolders /d 00000001 /t REG_DWORD /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location98" /v Path /d "C:\Users" /t REG_SZ /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location97" /v AllowSubFolders /d 00000001 /t REG_DWORD /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Office\%oVer%\Excel\Security\Trusted Locations\Location97" /v Path /d "D:\\" /t REG_SZ /f
goto :EOF

Thanks again!

Last edited by Eehixohw (09 Jun 2016 10:36)

Offline

#4 09 Jun 2016 13:19

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: Check MS Office Version in Registry

Oops ... yes that was meant to be

SET "oVer=%~1"

cmd | *sh | ruby | chef

Offline

#5 10 Jun 2016 12:16

Eehixohw
Member
Registered: 25 Sep 2011
Posts: 40

Re: Check MS Office Version in Registry

Tested and working. Thanks!

Offline

Board footer

Powered by