Best way to get file type association in Windows 10 from command line?

别来无恙 提交于 2021-02-19 01:54:45

问题


I am aware that I can use assoc and ftype on the command line to get the file type assocation. So when i do:

I am under the impression that .html files are opened with iexplorer.

However html files are opening with chrome since chrome has been set as the default app for html files.

Why is ftype giving me iexplorer when indeed the program opens with chrome?


回答1:


It seems that ftype and assoc are pretty useless on systems running Windows 8 or later.

This is due to the fact that Microsoft decided in Windows 8 that users should be able to set default programs only via the built in GUI. This probably was due to security reasons and trouble with applications hijacking file type associations.

Therefore a new registry key was introduced and Windows now writes the user choice to

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\<extension>\UserChoice

The key contains a Prog-Id and a Hash Value. The correct Hash value proves that the UserChoice ProgId value was set by the user, and not by any other application. If the hash is invalid, windows will reset the user choice to the default application.

The ftype command however is not aware of the above registry key.

It reads the HKCR\htmlfile\shell\open\command\(Default) registry key and prints out the result.

Therefore the results of the ftype command therefore are not usuable to determine which application is associated with a specific file extension.




回答2:


I found that if I rename or delete a file association in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\\UserChoice I can get windows to look at the ftype / assoc definitions and work as I want it.
The problem with the UserChoice key is, that I cannot run perl on .pl extension as I can with ftype/assoc.
E. g. I use the setup below to run my perl programs with .pl extensions:

>assoc .pl  
.pl=Perl  
>ftype perl  
perl="C:\Perl64\bin\perl.exe" "%1" %*  


来源:https://stackoverflow.com/questions/51715292/best-way-to-get-file-type-association-in-windows-10-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!