You are not logged in.
Pages: 1
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
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
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
Oops ... yes that was meant to be
SET "oVer=%~1"
cmd | *sh | ruby | chef
Offline
Tested and working. Thanks!
Offline
Pages: 1