Windows 7 file extension association

后端 未结 4 1540
心在旅途
心在旅途 2021-02-06 05:59

I am referring specifically to windows 7.

I have code that associates a certain extension with my application as proposed by webJose on the following page: What registry

相关标签:
4条回答
  • 2021-02-06 06:11

    Deleting UserChoice should revert the default program to the standard file association keys (which starts with the ProgID in HKCU). Barring that you could also delete OpenWithList, which would be reverting with extreme prejudice.

    Edit: Check out Registry Key Security and Access Rights on MSDN, particularly the RegSetKeySecurity function. Remember that you'll need to grant yourself administrative control to the key before you can delete it.

    0 讨论(0)
  • 2021-02-06 06:19

    Well regarding file assoc in Window 7 a new 'problem' araised.

    It's one of this: You've to fight for your rights.

    Assuming you like to run

    REG.exe DELETE "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.mov\UserChoice" /f /va
    

    You'll get ACCESS DENYED. When you check security setting of the key in Regedit 'UserChoice' you'll see that there's a setting windows made for you, to deny 'set' for the current user. Well you maybe change/delete this setting in regedit and now you can delete UserChoice. However for programmer/scripters that setting is a little bitchy since there are now real tools to set ACLs in the registry. However here some workaround that at allows to delete keys with ACCESS DENYED (of course this only works incase you've the right to change permissions):

    ResetMovAssoc.cmd

    ::create 'empty.hiv' 
    REG ADD "HKCU\emptyKey" /f
    REG SAVE "HKCU\emptyKey" empty.hiv /y
    @REG DELETE "HKCU\emptyKey" /f >nul
    ::^-note you can add @[...] >nul to the other entries as well to run them quite
    
    :: Delete Reg key by replacing it with an empty hiv
    REG RESTORE "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.mov" empty.hiv
    del empty.hiv
    

    To summarize this the major thing here is REG RESTORE + Registry hive file containing just and empty key. In Regedit that'll equivalent to Import' with a just an empty registry structure file (Note: that's a hive file and not a *.reg file).

    0 讨论(0)
  • 2021-02-06 06:30

    Also on Windows 10, this command can't work:

    Reg.exe delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.m4v" /f
    

    The solution is to delete the SID key by running a BAT file under TrustedInstaller (with NSudo, PowerRun, etc):

    for /f "delims=\ tokens=2" %%A in ('reg query hku ^| findstr /i "S-1-5-21-" ^| findstr /v /i "_Classes"') do set SID=%%A
    Reg.exe delete "HKU\%SID%\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.m4v" /f
    

    P.S.: Thanks to @SecurityAndPrivacyGuru for sharing the SID detection command.

    0 讨论(0)
  • 2021-02-06 06:33

    My solution was not to try to delete the UserChoice key (only administrators can do it), but to delete the key the ProgId is pointing to. If the user made a choice in the past the ProgId has a value like Applications\*.exe. The non-admin can delete the key in a batch:

    REG DELETE HKCR\Applications\*.exe /f
    

    This might be a bit of a hack, but worked for me.

    0 讨论(0)
提交回复
热议问题