2010年3月19日 星期五

列出「我最近的文件」清單

我最近的文件:雞肋又容易侵犯隱私的功能,不論開過什麼見不得人的東東,該檔案的捷徑都會被收錄在這個地方。去觀察男性使用者的這個目錄可以對他的性癖有初步認識。
預設路徑
C:\Documents and Settings\<User Name>\Recent


XP:「開始」功能表右鍵->[內容]->[「開始」功能表]->[自訂]->[進階]->[最近的文件]
列出最近開啟的文件:取消勾選後,「最近的文件」項目將不會出現在「開始」功能表內
清除清單:清掉「最近的文件」中的記錄

開啟 regeidt 至
[HKEY_CURRENT_USER]→[Software]→[Microsoft]→[Windows]→[CurrentVersion]→[Policies]→[Explorer]
新增名為 NoRecentDocsMenu 的 DWORD,值為 1:隱藏上述「最近的文件」的設定區塊
新增名為 NoRecentDocsHistory 的 DWORD,值為 1:開啟過的檔案捷徑將不再收錄至「最近的文件」內

印出「最近的文件」內容
01#include <windows.h>
02#include <shlobj.h>
03#pragma comment ( lib, "shell32.lib" )
04 
05int _tmain( int argc, _TCHAR* argv[] ){
06    TCHAR path[MAX_PATH+1];
07    WIN32_FIND_DATA findData;
08    HANDLE hFind;
09 
10    if( SHGetSpecialFolderPath( NULL, path, CSIDL_RECENT, FALSE ) ){
11        _tprintf_s( _T("%s\n"), path );
12 
13        _tcscat_s( path, _T("\\*.*") );
14        hFind = FindFirstFile( path, &findData );
15        path[_tcslen( path )-3] = 0;
16 
17        do{
18            _tprintf_s( _T("%s%s\n"), path, findData.cFileName );
19        } while ( FindNextFile( hFind, &findData ) );
20 
21        if( hFind != INVALID_HANDLE_VALUE ){
22            FindClose( hFind );
23        }
24    }
25 
26    system( "pause" );
27    return 0;
28}


Output as text file in UTF-16LE: RecentList.txt
must define _UNICODE
01#include <windows.h>
02#include <shlobj.h>
03#pragma comment ( lib, "shell32.lib" )
04 
05int _tmain( int argc, _TCHAR* argv[] ){
06    FILE* pFile = NULL;
07    _tfopen_s( &pFile, _T("RecentList.txt"), _T("wb") );
08    if( !pFile ){
09        _tprintf_s( _T("Cannot open file" ) );
10        system( "pause" );
11        return 0;
12    }
13 
14    WORD BOM = 0xFEFF;
15    fwrite( &BOM, sizeof( WORD ), 1, pFile );
16 
17    TCHAR path[MAX_PATH+1];
18    WIN32_FIND_DATA findData;
19    HANDLE hFind;
20    if( SHGetSpecialFolderPath( NULL, path, CSIDL_RECENT, FALSE ) ){
21        _ftprintf_s( pFile, _T("%s\n"), path );
22 
23        _tcscat_s( path, _T("\\*.*") );
24        hFind = FindFirstFile( path, &findData );
25        path[_tcslen( path )-3] = 0;
26 
27        do{
28            _ftprintf_s( pFile, _T("%s%s\n"), path, findData.cFileName );
29        } while ( FindNextFile( hFind, &findData ) );
30 
31        if( hFind != INVALID_HANDLE_VALUE ){
32            FindClose( hFind );
33        }
34    }
35    fclose( pFile );
36 
37    return 0;
38}