简体   繁体   中英

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?

More specifically:

  • If I select adobe reader as default PDF viewer from file properties
  • String viewer1 = "Command .pdf" (running in command prompt)
  • Then I change to acrobat from file properties → change default program
  • String viewer2 = "Command .pdf" (running in command prompt)

So, 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.

Does any registry key exist, that stores default program path for specific file extension (.pdf)?

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
  2. ftype to get the default handler ftype jpegimage

Hope that helps. I suppose you could pipeline the two but I have no idea how thats done in 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 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 . You can read it from the registry like this:

reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pdf\UserChoice /v Progid

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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