Advertisement
LogicDaemon

Stop Resetting My Apps ahk rewrite

Oct 31st, 2016
1,044
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Stop Windows from associating its apps with file types and protocols
  2. ;via http://www.ghacks.net/2016/10/28/stop-resetting-my-apps/
  3. ;by LogicDaemon <www.logicdaemon.ru>
  4. ;This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License <http://creativecommons.org/licenses/by-sa/4.0/deed>.
  5. #NoEnv
  6.  
  7. global pkgBaseKey:="HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages"
  8.         ,assocList:=Object()
  9.         ,appList := Object()
  10.        
  11. Loop Reg, %pkgBaseKey%, K
  12. {
  13.     packageName:=A_LoopRegName
  14.     If(DeniedApp(packageName))
  15.         Loop Reg, %pkgBaseKey%\%packageName%, K
  16.             ListAppAssoc(packageName, A_LoopRegName)
  17.     Else
  18.         Loop Reg, %pkgBaseKey%\%packageName%, K
  19.             If (DeniedApp(A_LoopRegName))
  20.                 ListAppAssoc(packageName, A_LoopRegName)
  21. }
  22.  
  23. For appName, ftype in appList {
  24.     list .= appName . ": " . Trim(ftype, ",") . "`n"
  25. }
  26. MsgBox 0x24, Deny following associations?, %list%
  27.  
  28. IfMsgBox Yes
  29. {
  30.     For assocID in assocList {
  31.         RegWrite REG_SZ, HKEY_CURRENT_USER\SOFTWARE\Classes\%assocID%, NoOpenWith
  32.     }
  33. }
  34.  
  35. ListAppAssoc(packageName, appName) {
  36.     humanReadableAppName := appName = "App" ? packageName : appName
  37.     Loop Reg, %pkgBaseKey%\%packageName%\%appName%\Capabilities, K ; FileAssociations / URLAssociations / …
  38.         If (EndsWith(A_LoopRegName, "Associations")) {
  39.             Loop Reg, %pkgBaseKey%\%packageName%\%appName%\Capabilities\%A_LoopRegName%
  40.                 If ( !(BeginsWith(A_LoopRegName, "ms") || BeginsWith(A_LoopRegName, "microsoft") || BeginsWith(A_LoopRegName, "outlook")) ) {
  41.                     RegRead assocID
  42.                     assocList[assocID] := ""
  43.                     appList[humanReadableAppName] .= A_LoopRegName . ","
  44.                 }
  45.         }
  46. }
  47.  
  48. DeniedApp(appName) {
  49.     static DenyApps := [ "Microsoft.MicrosoftEdge"
  50.                         ,"Microsoft.Windows.Photos"
  51.                         ,"microsoft.windowslive.mail"
  52.                         ,"Microsoft.ZuneMusic"
  53.                         ,"Microsoft.ZuneVideo"]
  54.     For i,v in DenyApps {
  55.         If (appName = v || BeginsWith(appName, v . "_"))
  56.             return 1
  57.     }
  58.     return 0
  59. }
  60.  
  61. BeginsWith(longstr, shortstr) {
  62.     return SubStr(longstr, 1, StrLen(shortstr)) = shortstr
  63. }
  64.  
  65. EndsWith(longstr, shortstr) {
  66.     return SubStr(longstr, 1-StrLen(shortstr)) = shortstr
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement