通过VS code右击打开

在最初安装VS Code的时候没有勾选通过open with code的2个框框,导致无法在文件中右击通过VS Code打开。

  • 通过写.reg文件修改注册表—–>错误,显示没有与之关联的应用

  • 参考了lanlan—–>成功。

    尝试①:写.reg文件。

    注册表shell下有了vscode子目录,vscode的默认字段的值是open with code
    vscode目录下出现command子目录,command中默认字段的值是vscode的安装地址,icon的值也为安装地址

  • 右击open with code
    报错:默认应用设置未关联
    解决:使用管理员身份运行,仍旧此错误

  • 百度搜此错误,原因是要消除小箭头,在cmd运行

    ```  
    taskkill /f /im explorer.exe
    
    reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v 29 /d "C:\Windows\system32\imageres.dll,154" /t reg_sz /f
    
    reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v 29 /d "C:\Windows\system32\imageres.dll,154" /t reg_sz /f
    
    reg add "HKEY_CLASSES_ROOT\lnkfile" /v IsShortcut /t reg_sz /f
    
    reg add "HEKY_CLASSES_ROOT\piffile" /v IsShortcut /t reg_sz /f
    
    start explorer   
    ```  

错误:找不到piffile文件
解决:原因是没有IconCache.db ,此文件是图标缓存文件。

  • 百度,此文件为隐藏文件,需要勾选显示隐藏文件
    错误:仍旧没有
    解决:放弃寻找

    尝试②:写.bat文件,解决默认应用设置未关联

    先写这个,运行这个
    ```  
    taskkill /f /im explorer.exe
    reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v 29 /d "C:\Windows\system32\imageres.dll,154" /t reg_sz /f
    reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v 29 /d "C:\Windows\system32\imageres.dll,154" /t reg_sz /f
    reg add "HKEY_CLASSES_ROOT\lnkfile" /v IsShortcut /t reg_sz /f
    reg add "HEKY_CLASSES_ROOT\piffile" /v IsShortcut /t reg_sz /f
    start explorer  
    ```  
    保存为.bat文件
    再写这个,运行这个
    reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v 29 /d "%systemroot%\system32\imageres.dll,197" /t reg_sz /f
    taskkill /f /im explorer.exe
    attrib -s -r -h "%userprofile%\AppData\Local\iconcache.db"
    del "%userprofile%\AppData\Local\iconcache.db" /f /q
    start explorer
    pause
    保存为.bat文件
    错误:默认应用设置未关联
    解决:不解决,弃用使用.reg文件修改注册表

    自己手动修改注册表

  • win+regedite打开注册表计算机\HKEY_CLASSES_ROOT\Directory\Background\shell
  • 删除shell下的vscode目录
  • 新建Open With Code目录
  • Open With Code目录下建command子目录
  • command默认字段值为vscode安装目录
    比如"C:\Users\苏玉璠\AppData\Local\Programs\Microsoft VS Code\Code.exe" "%V"
  • 添加字符串字段名为icon,值为code.icon的位置 (可选步骤)
    我没有找到code.icon文件,没有进行此步操作,vscode仍然可以打开

VS code跟注册表都是自动保存,在修改注册表之前,为了避免错误,可以先copy一份注册表