How to find Microsoft Office path from command line
Asked Answered
C

3

6

I would like to use command line to locate the path of MS office. It should return something like C:\Program Files (x86)\Microsoft Office\Office14 which might differ to different users.

Tried using:

where WINWORD.EXE 
INFO: Could not find files for the given pattern(s).

for %i in (WINWORD.EXE) do @echo.   %~$PATH:i
No output

Thanks for any help

Collectivize answered 18/3, 2014 at 6:52 Comment(0)
S
9

One starting point is the registry entries for application registration

reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WINWORD.EXE" 
Sporangium answered 18/3, 2014 at 8:8 Comment(1)
In recent versions of Windows+Office this key seems to be blankPickel
H
1

You can try this command to get full executable path of winword.exe:

get-childitem "C:\Program Files*\Microsoft Office" -recurse | where {$_.Name -eq "winword.exe"} | select -first 1 | % { $_.FullName }
Hughhughes answered 28/9, 2020 at 10:23 Comment(0)
C
-1

Function that searches registry then searches files and outputs path as string. (Takes "EXE" as Arg as well)

WHERE is great, but slow. I found querying registry to be faster, but less reliable so I combined the two ideas into a function like so:

app_path_func.cmd:

@ECHO OFF
CLS

FOR /F "skip=2 tokens=1,2* USEBACKQ" %%N IN (`reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\%~1" /t REG_SZ  /v "Path"`) DO (
 IF /I "%%N" == "Path" (
  SET wherepath=%%P%~1
  GoTo Found
 )
)

FOR /F "tokens=* USEBACKQ" %%F IN (`where.exe %~1`) DO (
 SET wherepath=%%F
 GoTo Found
)

FOR /F "tokens=* USEBACKQ" %%F IN (`where.exe /R "%PROGRAMFILES%" %~1`) DO (
 SET wherepath=%%F
 GoTo Found
)

FOR /F "tokens=* USEBACKQ" %%F IN (`where.exe /R "%PROGRAMFILES(x86)%" %~1`) DO (
 SET wherepath=%%F
 GoTo Found
)

FOR /F "tokens=* USEBACKQ" %%F IN (`where.exe /R "%WINDIR%" %~1`) DO (
 SET wherepath=%%F
 GoTo Found
)

:Found
SET %2=%wherepath%
:End

Test:

@ECHO OFF
CLS

CALL "app_path_func.cmd" WINWORD.EXE PROGPATH
ECHO %PROGPATH%

PAUSE

Result:

C:\Program Files (x86)\Microsoft Office\Office15\WINWORD.EXE
Press any key to continue . . .

https://www.freesoftwareservers.com/display/FREES/Find+Executable+via+Batch+-+Microsoft+Office+Example+-+WINWORD+-+Find+Microsoft+Office+Path

Conceptacle answered 4/8, 2020 at 23:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.