我想使用命令行来定位MS office的路径。它应该返回C:\Program Files (x86)\Microsoft Office\Office14
之类的内容,这些内容可能因不同的用户而异。
尝试使用:
where WINWORD.EXE
INFO: Could not find files for the given pattern(s).
for %i in (WINWORD.EXE) do @echo. %~$PATH:i
No output
感谢您的帮助
答案 0 :(得分:2)
一个起点是应用程序注册的注册表项
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WINWORD.EXE"
答案 1 :(得分:0)
您可以尝试使用以下命令来获取winword.exe的完整可执行路径:
get-childitem "C:\Program Files*\Microsoft Office" -recurse | where {$_.Name -eq "winword.exe"} | select -first 1 | % { $_.FullName }
答案 2 :(得分:-1)
搜索注册表的功能,然后搜索文件并将路径输出为字符串。 (也将“ EXE”也称为Arg)
WHERE
很好,但是很慢。我发现查询注册表的速度更快,但可靠性较差,因此我将这两个想法合并为一个函数,如下所示:
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
测试:
@ECHO OFF
CLS
CALL "app_path_func.cmd" WINWORD.EXE PROGPATH
ECHO %PROGPATH%
PAUSE
结果:
C:\Program Files (x86)\Microsoft Office\Office15\WINWORD.EXE
Press any key to continue . . .