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:開啟過的檔案捷徑將不再收錄至「最近的文件」內

印出「最近的文件」內容

#include <windows.h>
#include <shlobj.h>
#pragma comment ( lib, "shell32.lib" )

int _tmain( int argc, _TCHAR* argv[] ){
TCHAR path[MAX_PATH+1];
WIN32_FIND_DATA findData;
HANDLE hFind;

if( SHGetSpecialFolderPath( NULL, path, CSIDL_RECENT, FALSE ) ){
_tprintf_s( _T("%s\n"), path );

_tcscat_s( path, _T("\\*.*") );
hFind = FindFirstFile( path, &findData );
path[_tcslen( path )-3] = 0;

do{
_tprintf_s( _T("%s%s\n"), path, findData.cFileName );
} while ( FindNextFile( hFind, &findData ) );

if( hFind != INVALID_HANDLE_VALUE ){
FindClose( hFind );
}
}

system( "pause" );
return 0;
}


Output as text file in UTF-16LE: RecentList.txt
must define _UNICODE

#include <windows.h>
#include <shlobj.h>
#pragma comment ( lib, "shell32.lib" )

int _tmain( int argc, _TCHAR* argv[] ){
FILE* pFile = NULL;
_tfopen_s( &pFile, _T("RecentList.txt"), _T("wb") );
if( !pFile ){
_tprintf_s( _T("Cannot open file" ) );
system( "pause" );
return 0;
}

WORD BOM = 0xFEFF;
fwrite( &BOM, sizeof( WORD ), 1, pFile );

TCHAR path[MAX_PATH+1];
WIN32_FIND_DATA findData;
HANDLE hFind;
if( SHGetSpecialFolderPath( NULL, path, CSIDL_RECENT, FALSE ) ){
_ftprintf_s( pFile, _T("%s\n"), path );

_tcscat_s( path, _T("\\*.*") );
hFind = FindFirstFile( path, &findData );
path[_tcslen( path )-3] = 0;

do{
_ftprintf_s( pFile, _T("%s%s\n"), path, findData.cFileName );
} while ( FindNextFile( hFind, &findData ) );

if( hFind != INVALID_HANDLE_VALUE ){
FindClose( hFind );
}
}
fclose( pFile );

return 0;
}