How do I set “default App” for a file extension to

2019-08-11 08:57发布

I have spent a very long time researching this. Most of the solutions were posted PRIOR to April 2018, and involved working your way through the "settings" to get to "Choose default Apps by file type".

Choose default Apps by file type

In previous attempts to assign an app to ".rex" I managed to assign it to Notepad. (At that time, I could not find any way to find an ".exe" on my C: drive.)

So as you can see, if you click on Notepad next to the .rex extension, the only option is to go to the "App store".

And as expected, if you click on App store, nothing is found...

App store - no app's found.

So from what I've read in multiple forums, PRIOR to April 2018, Windows 10 still had a way to "browse your hard drive" to find an ".exe". (Just like in older Windows versions.) After some update in April 2018, that capability no longer exists.

In the POST April 2018, has anyone found a way to assign a file extension to an ".exe" on the hard drive???

1条回答
Deceive 欺骗
2楼-- · 2019-08-11 09:11

I think this question would be more suitable for SuperUser (well, unless you want to do it via a program :) ).

Anyway, here's a way of doing things from console (cmd). I've tried it 1 or 2 years ago, I just tried it now, so it works regardless of Win (10) version.
Start the process from scratch:

  1. Open a Command Prompt Window. Create a new file that the OS doesn't know anything about. I chose the extension .zzz:

    e:\Work\Dev\StackOverflow\q052008516>ver
    
    Microsoft Windows [Version 10.0.17134.228]
    
    e:\Work\Dev\StackOverflow\q052008516>dir /b
    
    e:\Work\Dev\StackOverflow\q052008516>:: Create a dummy .zzz file
    e:\Work\Dev\StackOverflow\q052008516>echo Some dummy text>file.zzz
    
    e:\Work\Dev\StackOverflow\q052008516>dir /b
    file.zzz
    


  1. Try opening the file (DblClick) from a file browser (it's not relevant, but I use Total Commander), or by typing its name in cmd. That will yield the dreaded dialog:

    Unknown file open dialog


  1. Create a new file type and associate our extension with it. [MS.Docs]: assoc utility is used to do the job. First, check if such association doesn't already exist:

    e:\Work\Dev\StackOverflow\q052008516>:: No output means no association
    e:\Work\Dev\StackOverflow\q052008516>assoc | findstr ".zzz"
    
    e:\Work\Dev\StackOverflow\q052008516>:: Same command for a different extension
    e:\Work\Dev\StackOverflow\q052008516>assoc | findstr ".txt"
    .dic=txtfile
    .exc=txtfile
    .log=txtfile
    .scp=txtfile
    .txt=txtfile
    .wtx=txtfile
    
    e:\Work\Dev\StackOverflow\q052008516>:: Create a new FileType (ZZZFile) and associate our extension with it
    e:\Work\Dev\StackOverflow\q052008516>assoc .zzz=ZZZFile
    .zzz=ZZZFile
    
    e:\Work\Dev\StackOverflow\q052008516>assoc | findstr ".zzz"
    .zzz=ZZZFile
    

    No change when trying to open the file.


  1. Associate the file type (ZZZFile, from previous step) with a command. Use the [MS.Docs]: ftype tool for the task. Again, check if the file type is not already associated (this only makes sense if the file type existed before previous step):

    e:\Work\Dev\StackOverflow\q052008516>:: As usual, no output means no association
    e:\Work\Dev\StackOverflow\q052008516>ftype | findstr ZZZFile
    
    e:\Work\Dev\StackOverflow\q052008516>:: Same thing for txtfile
    e:\Work\Dev\StackOverflow\q052008516>ftype | findstr txtfile
    txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1
    
    e:\Work\Dev\StackOverflow\q052008516>:: Associate ZZZFile with notepad
    e:\Work\Dev\StackOverflow\q052008516>ftype ZZZFile=%SystemRoot%\system32\notepad.exe %1
    ZZZFile=C:\WINDOWS\system32\notepad.exe %1
    
    e:\Work\Dev\StackOverflow\q052008516>ftype | findstr ZZZFile
    ZZZFile=C:\WINDOWS\system32\notepad.exe %1
    


  1. Try opening the file again (from cmd), and voilà:

    Notepad


Summary:

In order to open with notepad.exe files having .zzz extension, there are only 2 commands that need to be remembered from this whole (and pretty long) answer:

  • assoc .zzz=ZZZFile
  • ftype ZZZFile=%SystemRoot%\system32\notepad.exe %1

Notes:

  • My user has (super) administrative privileges, but I guess they shouldn't impact differently depending where the action is performed from (cmd or UI (if possible)), in other words users that don't have the required privileges, won't be able to do it, no matter what they would try
  • Apparently, there is a (pretty dark) nebula on this topic, that my knowledge wasn't yet able to "decipher". In my example, I constantly compare the .zzz results to .txt. Yet a big surprise: Notepad++ and not Notepad is used to open txtfile (.txt only), in spite of the above output

@EDIT0:

I did a little more digging on the .txt mystery. Facts:

  • ftype shows Notepad as opening program
  • It is actually opened by Notepad++ (in cmd and PS)
  • In Choose default apps by file type, Notepad++ is shown

So apparently, it's more than meets the eye (over the years, I got used to MS's way of doing things which in some cases seems to be (but maybe it's me who didn't have all the pieces) ilogic). I've also found out many resources like:

I couldn't find anywhere a clear algorithm of how an executable is chosen to run a file with a certain extension. I can think that the 2 keys above are queried, but I'm 100% sure there's more. Not to mention that I've ran into an even stranger problem (for a regular user on my Win 10), for .py files:

  • ftype (and assoc) reported everything as above
  • In Choose default apps by file type, Python was shown (just like in my Super Admin user's case)
  • Attempting to run the file from cmd, yielded the dialog at the beginning
  • It worked from PS

Sadly, I selected Python from the dialog, before taking a look at the reg keys (and now it works), so I can't do any more debugging (and also, switching users is annoying).

查看更多
登录 后发表回答