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


今天閑得蛋疼清理了一下右鍵菜單,於是在之后某時刻使用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=r'Z:\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 ,真是藍瘦……


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM