Question

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

Was it helpful?

Solution

One starting point is the registry entries for application registration

reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WINWORD.EXE" 

OTHER TIPS

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 }

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top