Wednesday, June 5, 2013

Path to Microsoft Office Folder

If you want to perform some manipulations with MS Office or just check the existance of this software on a computer running Windows, you don't have to find the path to Microsoft Office folder manually. All you need to do is running quite a small batch script that you can see below:
for /L %%i in (15,-1,7) do call :GetPath %%i
goto :end
:GetPath
reg query HKLM\Software\Microsoft\Office\%1.0\Common\InstallRoot /v Path
if errorlevel 1 goto :end
acregl.exe "%TEMP%\SetPath.cmd" OFFICE_PATH HKLM\Software\Microsoft\Office\%1.0\Common\InstallRoot Path ""
call "%TEMP%\SetPath.cmd"
del "%TEMP%\SetPath.cmd" 2>&1
:end

As far as you can see, this script searches for path to Microsoft Office folder for different versions of Microsoft Office, from 7.0 (MS Office 97) to 15 (MS Office 2013). For future versions you should just increase the starting number in 'for' loop at the first  line of this script.
After executing this script you'll find path to Microsoft Office folder in OFFICE_PATH variable.
Also you need to place acregl.exe to the folder with your batch file before executing this script. You can find it in your 'Windows' folder on system drive.
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

No comments:

Post a Comment

Translate