緣起
vs
有一個功能 —— 在起始頁會顯示最近打開的工程列表,方便用戶快速打開之前打開過的工程文件。但是打開的工程文件多了,想要找到自己需要的工程文件也不是那么容易的,要是能把之前打開的記錄都清理干凈該有多好啊。本文記錄了我在查找vs2019
相關設置存儲位置的調查過程 。對於vs2017
以前的版本,對應的設置是保存在注冊表中的,從vs2017
開始,不再保存在注冊表,而是存儲在本地配置文件中。到底存儲在哪里了呢?我們一起來看看吧!
調查
調查這種問題,當然優先考慮process monitor
了,對吧?
使用process monitor
-
打開
process monitor
,開始捕獲事件。 -
打開
vs2019
,直到顯示出最近打開的文件列表。 -
停止捕獲。
-
查找
vs2019
訪問過的注冊表項記錄,根據Result
那列是SUCCESS
進行過濾,找了一圈沒發現可疑項,有幾類事件非常像,但是不能進一步得到更有效的信息。

上圖黃色高亮部分\REGISTERY\A\
對應的注冊表項很奇怪,不能直接跳轉過去(一般在Path
列中的記錄都可以通過右鍵菜單的Jump To...
跳轉過去),而且在注冊表中搜索不到此鍵。關於\REGISTERY\A\
的相關資料,會在文末給出。
- 雖然在注冊表事件中沒有找到答案,我們還可以在文件讀寫事件里搜索。在
Path列
按CTRL+F
,搜索關鍵字VsClearRecentProjects.sln
,沒找到任何記錄,在Detail列
同樣沒搜到任何記錄。這是什么情況?:confounded:
看來這次不能通過process monitor
直接找到答案了(其實,process monitor
已經捕獲了相關的事件,只不過我沒能通過已知信息找到它)。我們還有什么辦法呢?vs
應該不至於對這么簡單的配置項進行加密存儲,我們還可以在整個電腦中搜索與VsClearRecentProjects.sln
相關的內容。
在注冊表中搜索
首先,在注冊表中搜索VsClearRecentProjects.sln
,結果如下:

從搜索結果來看,沒有一項是跟
vs
有關的,看來從注冊表中我們沒能得到什么有價值的線索。
繼續在磁盤文件中搜索
我們可以通過FileLocator
對磁盤文件內容進行搜索,結果如下:

Wow,搜到不少相關結果。對每一項進行檢查后發現ApplicationPrivateSettings.xml
最有可能。
驗證
關閉vs2019
,刪除ApplicationPrivateSettings.xml
,重新啟動vs2019
,不再顯示最近打開的工程列表。搞定!
{% note info %}
說明:對於vs2017
及以后版本,相關配置存儲在配置文件中,大家可以在自己機器上搜索該文件,刪除即可。
{% endnote %}
{% note warning %}
警告:該文件中不僅僅包含最近打開的工程文件,還包含其它設置!謹慎刪除(刪了也沒什么事)!懶人隨意。
{% endnote %}
清理
知道了存儲位置,清理起來就簡單了。
腳本
我們可以使用以下腳本來清理,本腳本摘自網絡,我做了注釋及補充完善。
@echo off
:: vs2005
@REGDelete HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\FileMRUList /va /f
@REGDelete HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\ProjectMRUList /va /f
:: vs2008
@REGDelete HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\FileMRUList /va /f
@REGDelete HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\ProjectMRUList /va /f
:: vs2010
@REGDelete HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\FileMRUList /va /f
@REGDelete HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\ProjectMRUList /va /f
:: vs2012
@REGDelete HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\FileMRUList /va /f
@REGDelete HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\ProjectMRUList /va /f
:: vs2013
@REGDelete HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\FileMRUList /va /f
@REGDelete HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\ProjectMRUList /va /f
:: vs2015
@REGDelete HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0\FileMRUList /va /f
@REGDelete HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0\ProjectMRUList /va /f
:: vs2019 (需要變成你自己電腦上的路徑)
@del C:\Users\BCN\AppData\Local\Microsoft\VisualStudio\16.0_20f56984\ApplicationPrivateSettings.xml
工具
如果你不想手動查找ApplicationPrivateSettings.xml
的路徑,可以使用我寫的超級簡單的winform
程序。github
地址 https://github.com/BianChengNan/VsClearRecentProjects ,歡迎fork
。

最后,貼出一份vs名稱
與內部版本號
的對應關系,以后可能用的到。

關於\REGISTRY\A
StackExchange
上的帖子 What does the path '\REGISTRY\A\…' in Sysinternals Procmon log mean?
中的回答對此做了很有幫助的介紹,摘錄如下:
It is application hive, which can be seen in volatilty by no name! pplication hives are registry hives loaded by user-mode applications to store application-specific state data. An application calls the RegLoadAppKey function to load an application hive.
more info on
http://msdn.microsoft.com/en-us/library/windows/hardware/jj673019%28v=vs.85%29.aspx
提問者最后的回答更加明確,引用了MSDN Forum
上的問答。為了方便大家,也摘錄如下:
Hi,
The increase the isolation and resilience of VS 2017, it uses now a private registry hive. Internally VS uses a redirection and while for VS extensions (which are dlls) this is transparent, for external processes (that are exes), this causes them not to work.To change values in the private registry hive by hand, you can use regedit.exe to load a private hive. You need to select the HKEY_USERS node, and click the File > Load Hive… menu. You select the privateregistry.bin file, give a name to the hive (I entered “VS2017PrivateRegistry”) and now you can see the 15.0_Config key populated as usual (note: use File > Unload Hive when done):
To change values in the private registry hive programmatically you need either to build an extension for VS or if you want to use an external exe you need to use the RegLoadAppKey function or avoid using the registry directly and use the External Settings Manager. See the section “Change: Reduce registry impact” in Breaking Changes in Visual Studio 2017 extensibility.
總結
FileLocator
可以快速搜索文件內容,everything
可以根據文件名進行快速搜索。- 條條大路通羅馬,有時候簡單粗暴的方法反而更有效。
- 關於
\REGISTRY\A
,你學到了嗎?:blush: