[英]Command to find default program related to file(.pdf) using command line in windows OS
Is there any command through which I can find that user has selected a particular program (eg Adobe reader/Adobe acrobat) as default program for a particular file extension (eg .pdf) in Windows? 是否有任何命令我可以通过它找到用户选择特定程序(例如Adobe reader / Adobe acrobat)作为Windows中特定文件扩展名(例如.pdf)的默认程序?
More specifically: 进一步来说:
adobe reader
as default PDF viewer
from file properties adobe reader
作为默认PDF viewer
viewer1 = "Command .pdf"
(running in command prompt) viewer1 = "Command .pdf"
(在命令提示符下运行) viewer2 = "Command .pdf"
(running in command prompt) viewer2 = "Command .pdf"
(在命令提示符下运行) So, viewer1 != viewer2 所以,viewer1!= viewer2
I am working in Java swing, so if there is any library or way to find default program selected to .pdf file, that would also helpful for me. 我正在使用Java swing,所以如果有任何库或方法可以找到选择.pdf文件的默认程序,那对我也有帮助。
Does any registry key exist, that stores default program path for specific file extension (.pdf)? 是否存在任何存储特定文件扩展名(.pdf)的默认程序路径的注册表项?
EDITED EDITED
Okay so I missed a part here. 好的,所以我在这里错过了一个部分。 It consists of two commands.
它由两个命令组成。
assoc
to get the filetype association with the extension eg .jpg=jpegimage
assoc
以获取与扩展名的文件类型关联,例如.jpg=jpegimage
ftype
to get the default handler ftype jpegimage
ftype
获取默认处理程序ftype jpegimage
Hope that helps. 希望有所帮助。 I suppose you could pipeline the two but I have no idea how thats done in Windows.
我想你可以管道这两个,但我不知道在Windows中如何做到这一点。
The default command associated with a given extension can be determined like this: 与给定扩展名关联的默认命令可以像这样确定:
for /F "tokens=2 delims==" %a in ('assoc .pdf') do ftype %a
Change %a
to %%a
if you want to use this in a batch file. 如果要在批处理文件中使用此项,请将
%a
更改为%%a
。
A manual override of the associated command via the file's properties, however, seems to be stored elsewhere (in the Progid
value of the key HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.pdf\\UserChoice
to be specific), so it won't be detected by assoc
. 但是,通过文件属性手动覆盖相关命令似乎存储在别处(在特定的键
HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.pdf\\UserChoice
的Progid
值中),所以它不会被assoc
检测到。 You can read it from the registry like this: 您可以从注册表中读取它,如下所示:
reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pdf\UserChoice /v Progid
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.