1. 程式人生 > >[Windows10]記一次修復註冊表相關血案:該文件沒有與之關聯的應用來執行該操作。請安裝應用,若已經安裝應用,請在“默認應用設置”頁面中創建關聯。

[Windows10]記一次修復註冊表相關血案:該文件沒有與之關聯的應用來執行該操作。請安裝應用,若已經安裝應用,請在“默認應用設置”頁面中創建關聯。

src 相關 overflow 還在 一次 註冊表 forum sin 嘗試

今天閑得蛋疼清理了一下右鍵菜單,於是在之後某時刻使用Everything的“雙擊路徑列打開目錄”功能時發現異常:

[Window Title]
Everything.exe

[Content]
該文件沒有與之關聯的應用來執行該操作。請安裝應用,若已經安裝應用,請在“默認應用設置”頁面中創建關聯。

[確定]

技術分享圖片

接下來的自救過程實在曲折,中間查到Everything是調用Windows API SHOpenFolderAndSelectItems 失敗導致彈這個錯誤(Automatically open folder again with "Open path with double click")。

技術分享圖片

我甚至還在網上找了一份可以調用這個API的代碼,運行這份測試代碼時出現了幾乎完全一樣的錯誤窗口。

 1 #!python3
 2 # https://stackoverflow.com/questions/20565401/how-to-access-shopenfolderandselectitems-by-ctypes
 3 
 4 import win32api
 5 from win32com.shell import shell, shellcon
 6 import os
 7 
 8 def launch_file_explorer(path, files):
 9
‘‘‘ 10 Given a absolute base path and names of its children (no path), open 11 up one File Explorer window with all the child files selected 12 ‘‘‘ 13 folder_pidl = shell.SHILCreateFromPath(path,0)[0] 14 desktop = shell.SHGetDesktopFolder() 15 shell_folder = desktop.BindToObject(folder_pidl, None,shell.IID_IShellFolder)
16 name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, shellcon.SHGDN_FORPARSING|shellcon.SHGDN_INFOLDER), item) for item in shell_folder]) 17 print("name_to_item_mapping: {0}".format(name_to_item_mapping)) 18 to_show = [] 19 for file in files: 20 if file in name_to_item_mapping: 21 to_show.append(name_to_item_mapping[file]) 22 else: 23 raise Exception(File: "%s" not found in "%s" % (file, path)) 24 25 print("to_show: {0}".format(to_show)) 26 print("call SHOpenFolderAndSelectItems()") 27 result = shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0) 28 last_error = win32api.GetLastError() 29 print("SHOpenFolderAndSelectItems returned {0}".format(result)) 30 31 p=rZ:\SHARE 32 print(os.listdir(p)) 33 launch_file_explorer(p, os.listdir(p))

技術分享圖片

此時其實離最終答案已經不遠了,可我卻沒有及時發現,折騰到後期甚至懷疑並不是註冊表引起的問題,畢竟早已經嘗試過把右鍵菜單還原回去了。

直至嘗試系統還原並且失敗後,五味雜陳地一邊看著這個窗口一邊備份文件時才忽然靈光乍現!

技術分享圖片

既然可能是操作註冊表導致的故障,那麽找一份OK的註冊表來對比或許還有救。

於是從另一臺正常的Windows 10 PC裏導出 HKEY_CLASSES_ROOT\Folder ,跟這裏故障機導出的文件對比:

技術分享圖片

把天殺的 none 刪除後故障成功排除!

此時回想起出問題的API SHOpenFolderAndSelectItems 名字裏帶著 Folder ,真是藍瘦……

[Windows10]記一次修復註冊表相關血案:該文件沒有與之關聯的應用來執行該操作。請安裝應用,若已經安裝應用,請在“默認應用設置”頁面中創建關聯。