简体   繁体   English

使用Windows操作系统中的命令行查找与文件(.pdf)相关的默认程序的命令

[英]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 / Adob​​e acrobat)作为Windows中特定文件扩展名(例如.pdf)的默认程序?

More specifically: 进一步来说:

  • If I select adobe reader as default PDF viewer from file properties 如果我从文件属性中选择adobe reader作为默认PDF viewer
  • String viewer1 = "Command .pdf" (running in command prompt) String viewer1 = "Command .pdf" (在命令提示符下运行)
  • Then I change to acrobat from file properties → change default program 然后我从文件属性→更改默认程序更改为acrobat
  • String viewer2 = "Command .pdf" (running in command prompt) String 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. 它由两个命令组成。

  1. assoc to get the filetype association with the extension eg .jpg=jpegimage assoc以获取与扩展名的文件类型关联,例如.jpg=jpegimage
  2. 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\\UserChoiceProgid值中),所以它不会被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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM