经过以下两步就可以使一个普通文件夹具有类似垃圾桶的外观和行为。
1)生成一个Desktop.ini文件,使其包含如下内容。
[.ShellClassInfo] CLSID={645FF040-5081-101B-9F08-00AA002F954E}
2)使用Attrib +s <目录名>将该目录设置为系统属性。
以下是使用编程方法实现所需的源代码。
// Heres a Sample program: 2 files // 1. FolderDisguises.h // 2. CreateFolderDisguises.cpp // /*****************************************************/ // FolderDisguises.h #pragma once #include #include #include
#include #pragma comment(lib, "Rpcrt4.lib")
CONST LPTSTR GUID_ShellLink = "{00021401-0000-0000-C000-000000000046}"; CONST LPTSTR GUID_MyComputer = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}"; CONST LPTSTR GUID_Internet = "{871C5380-42A0-1069-A2EA-08002B30309D}"; CONST LPTSTR GUID_RecycleBin = "{645FF040-5081-101B-9F08-00AA002F954E}"; CONST LPTSTR GUID_ControlPanel = "{21EC2020-3AEA-1069-A2DD-08002B30309D}"; CONST LPTSTR GUID_NetworkPlaces = "{208D2C60-3AEA-1069-A2D7-08002B30309D}"; CONST LPTSTR GUID_MyDocuments = "{450D8FBA-AD25-11D0-98A8-0800361B1103}"; //CONST LPTSTR GUID_ShellFSFolder = "{F3364BA0-65B9-11CE-A9BA-00AA004AE837}"; //CONST LPTSTR GUID_ShellDesktop = "{00021400-0000-0000-C000-000000000046}"; //CONST LPTSTR GUID_NetworkDomain = "{46e06680-4bf0-11d1-83ee-00a0c90dc849}"; //CONST LPTSTR GUID_NetworkServer = "{c0542a90-4bf0-11d1-83ee-00a0c90dc849}"; //CONST LPTSTR GUID_NetworkShare = "{54a754c0-4bf1-11d1-83ee-00a0c90dc849}";
CONST LPTSTR DESKTOP_INI_HEADER = _T("[.ShellClassInfo]\r\n" "CLSID=");
BOOL CreateSystemFolder(LPTSTR pFolder) { _tprintf("\n\n ---- Creating : %s", pFolder); if (!CreateDirectory(pFolder, NULL)) { _tprintf("\n\t Could not create folder: %s", pFolder); return FALSE; } if (!SetFileAttributes(pFolder, FILE_ATTRIBUTE_SYSTEM)) { _tprintf("Could not set folder as SYSTEM: %s", pFolder); return FALSE; } return TRUE; }
BOOL CreateDesktopIni(LPTSTR szFolderPath, LPTSTR szClassID) { TCHAR szFilePath[MAX_PATH] = {0}; lstrcpy(szFilePath, szFolderPath); lstrcat(szFilePath, _T("Desktop.ini"));
HANDLE hFile = CreateFile(szFilePath, GENERIC_READ|GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { _tprintf("\n Error creating desktop.ini. Error: %i", GetLastError()); return FALSE; }
DWORD dwWritten = 0; DWORD dwBufSize = 0; TCHAR szData [1024]; lstrcpy(szData, DESKTOP_INI_HEADER); lstrcat(szData, szClassID); dwBufSize = lstrlen(szData) * sizeof(TCHAR); BOOL bRes = WriteFile(hFile, (LPCVOID) szData, dwBufSize, &dwWritten, NULL); if (dwWritten != dwBufSize || !bRes) { _tprintf("\n Error writing to desktop.ini \n GetLastError: %i", GetLastError()); CloseHandle(hFile); return FALSE; }
CloseHandle(hFile); return TRUE; }
////////////////////////////////////////////////////////////////////// // Function : CreateFolderDisguise // Date : Jun 26, 2006 // Author : Kevin W. // Parameters : szCurrDir - Path to create the sub-folder in // szDirName - Name give to the new sub-folder // Description : // Creates a System folder and the Desktop.ini populated w/ the // specified CLSID. // // ////////////////////////////////////////////////////////////////////// BOOL CreateFolderDisguise(IN LPTSTR szCurrDir, IN LPTSTR szDirName, IN LPTSTR szClassID) { TCHAR szFolder[MAX_PATH] = {0}; lstrcpy(szFolder, szCurrDir); lstrcat(szFolder, _T("\\")); lstrcat(szFolder, szDirName); lstrcat(szFolder, _T("\\"));
if (!CreateSystemFolder(szFolder)) { return FALSE; } if (!CreateDesktopIni(szFolder, szClassID)) { return FALSE; } return TRUE; } ////////////////////////////////////////////////////////////////////// // Function : ConvertUuidToString // Date : Jun 26, 2006 // Author : Kevin W. // Parameters : // Description : // // Wrapper around the RPC API to convert GUID to String // ////////////////////////////////////////////////////////////////////// BOOL ConvertUuidToString(IN UUID uuid, OUT LPTSTR pClassID) { unsigned char __RPC_FAR * ppUidString; UuidToString(&uuid, &ppUidString ); lstrcpy(pClassID, _T("{")); lstrcat(pClassID, (LPCSTR) ppUidString); lstrcat(pClassID, _T("}")); RpcStringFree(&ppUidString); return TRUE; } BOOL CreateFolderDisguise(IN LPTSTR szCurrDir, IN LPTSTR szDirName, IN UUID uid) { TCHAR szGuid[MAX_PATH] = {0}; ConvertUuidToString(uid, &szGuid[0]); return CreateFolderDisguise(szCurrDir, szDirName, szGuid); } BOOL CreateFolderDisguise(IN LPTSTR szCurrDir, IN UUID uid) { TCHAR szGuid[MAX_PATH] = {0}; ConvertUuidToString(uid, &szGuid[0]); return CreateFolderDisguise(szCurrDir, szGuid, szGuid); }
/********************************************************/ /** FILE 2, MAIN ****/ /********************************************************/ // // CreateFolderDisguises.cpp : // #include #include #include #include #include #include "FolderDisguises.h" int _tmain(int argc, _TCHAR* argv[]) { TCHAR szFolder[MAX_PATH] = {0}; TCHAR szCurrDir[MAX_PATH] = {0}; TCHAR szFilePath[MAX_PATH] = {0};
GetCurrentDirectory(MAX_PATH, &szCurrDir[0]); lstrcat(szCurrDir, _T("\\Disguised Folders")); CreateDirectory(szCurrDir, NULL);
CreateFolderDisguise(szCurrDir, _T("My Computer"), GUID_MyComputer); CreateFolderDisguise(szCurrDir, _T("Shell Link"), GUID_ShellLink); CreateFolderDisguise(szCurrDir, _T("NetworkPlaces"), GUID_NetworkPlaces); CreateFolderDisguise(szCurrDir, _T("Internet Explorer"), GUID_Internet); CreateFolderDisguise(szCurrDir, _T("Control Panel"), GUID_ControlPanel); CreateFolderDisguise(szCurrDir, _T("Recycle Bin"), GUID_RecycleBin); CreateFolderDisguise(szCurrDir, _T("My Documents"), GUID_MyDocuments);
/****************************************************** * none of these did anything * //CreateFolderDisguise(szCurrDir, _T("GUID_ShellDesktop"), GUID_ShellDesktop); //CreateFolderDisguise(szCurrDir, _T("GUID_NetworkDomain"), GUID_NetworkDomain); //CreateFolderDisguise(szCurrDir, _T("GUID_NetworkServer"), GUID_NetworkServer); //CreateFolderDisguise(szCurrDir, _T("GUID_NetworkShare"), GUID_NetworkShare); //CreateFolderDisguise(szCurrDir, _T("GUID_ShellFSFolder"), GUID_ShellFSFolder); CreateFolderDisguise(szCurrDir, IID_IBriefcaseStg); CreateFolderDisguise(szCurrDir, IID_IShellView2); CreateFolderDisguise(szCurrDir, IID_IShellLinkDataList); CreateFolderDisguise(szCurrDir, IID_IResolveShellLink); CreateFolderDisguise(szCurrDir, IID_IURLSearchHook); CreateFolderDisguise(szCurrDir, IID_ISearchContext); CreateFolderDisguise(szCurrDir, IID_IURLSearchHook2); CreateFolderDisguise(szCurrDir, IID_IDelegateFolder); CreateFolderDisguise(szCurrDir, IID_IDefViewID); CreateFolderDisguise(szCurrDir, CLSID_FolderShortcut); CreateFolderDisguise(szCurrDir, CLSID_StgFolder); CreateFolderDisguise(szCurrDir, IID_IInputObject); CreateFolderDisguise(szCurrDir, IID_IInputObjectSite); CreateFolderDisguise(szCurrDir, IID_IDockingWindowSite); CreateFolderDisguise(szCurrDir, IID_IDockingWindowFrame); CreateFolderDisguise(szCurrDir, IID_IShellIconOverlay); CreateFolderDisguise(szCurrDir, IID_IShellIconOverlayIdentifier); CreateFolderDisguise(szCurrDir, IID_ICommDlgBrowser2); CreateFolderDisguise(szCurrDir, IID_IShellFolderViewCB); CreateFolderDisguise(szCurrDir, IID_IPersistFolder3); CreateFolderDisguise(szCurrDir, CLSID_CFSIconOverlayManager); CreateFolderDisguise(szCurrDir, IID_IShellIconOverlayManager); CreateFolderDisguise(szCurrDir, IID_IRunnableTask); CreateFolderDisguise(szCurrDir, IID_IThumbnailCapture); CreateFolderDisguise(szCurrDir, IID_IShellImageStore); CreateFolderDisguise(szCurrDir, IID_IEnumShellImageStore); CreateFolderDisguise(szCurrDir, CLSID_ShellThumbnailDiskCache); CreateFolderDisguise(szCurrDir, IID_IContextMenu3); CreateFolderDisguise(szCurrDir, SID_DefView); CreateFolderDisguise(szCurrDir, CGID_DefView); CreateFolderDisguise(szCurrDir, CLSID_MenuBand); CreateFolderDisguise(szCurrDir, IID_IShellFolderBand); CreateFolderDisguise(szCurrDir, IID_IDefViewFrame); CreateFolderDisguise(szCurrDir, VID_LargeIcons); CreateFolderDisguise(szCurrDir, VID_SmallIcons); CreateFolderDisguise(szCurrDir, VID_List); CreateFolderDisguise(szCurrDir, VID_Details); CreateFolderDisguise(szCurrDir, VID_Tile); CreateFolderDisguise(szCurrDir, VID_Thumbnails); CreateFolderDisguise(szCurrDir, VID_ThumbStrip); */
/* these didn't do anything either CreateFolderDisguise(szCurrDir, "{10339516-2894-11d2-9039-00C04F8EEB3E}", "{10339516-2894-11d2-9039-00C04F8EEB3E}"); CreateFolderDisguise(szCurrDir, "{CEF04FDF-FE72-11d2-87A5-00C04F6837CF}", "{CEF04FDF-FE72-11d2-87A5-00C04F6837CF}"); CreateFolderDisguise(szCurrDir, "{63B51F81-C868-11D0-999C-00C04FD655E1}", "{63B51F81-C868-11D0-999C-00C04FD655E1}"); CreateFolderDisguise(szCurrDir, "{85788D00-6807-11d0-B810-00C04FD706EC}", "{85788D00-6807-11d0-B810-00C04FD706EC}"); CreateFolderDisguise(szCurrDir, "{4ea39266-7211-409f-b622-f63dbd16c533}", "{4ea39266-7211-409f-b622-f63dbd16c533}"); CreateFolderDisguise(szCurrDir, "{48C8118C-B924-11d1-98D5-00C04FB687DA}", "{48C8118C-B924-11d1-98D5-00C04FB687DA}"); CreateFolderDisguise(szCurrDir, "{6DFD582B-92E3-11d1-98A3-00C04FB687DA}", "{6DFD582B-92E3-11d1-98A3-00C04FB687DA}"); CreateFolderDisguise(szCurrDir, "{1EBDCF80-A200-11d0-A3A4-00C04FD706EC}", "{1EBDCF80-A200-11d0-A3A4-00C04FD706EC}"); CreateFolderDisguise(szCurrDir, "{BCFCE0A0-EC17-11d0-8D10-00A0C90F2719}", "{BCFCE0A0-EC17-11d0-8D10-00A0C90F2719}"); CreateFolderDisguise(szCurrDir, "{7FE80CC8-C247-11d0-B93A-00A0C90312E1}", "{7FE80CC8-C247-11d0-B93A-00A0C90312E1}"); CreateFolderDisguise(szCurrDir, "{8BEBB290-52D0-11d0-B7F4-00C04FD706EC}", "{8BEBB290-52D0-11d0-B7F4-00C04FD706EC}"); CreateFolderDisguise(szCurrDir, "{8EEFA624-D1E9-445B-94B7-74FBCE2EA11A}", "{8EEFA624-D1E9-445B-94B7-74FBCE2EA11A}"); CreateFolderDisguise(szCurrDir, "{91956D21-9276-11d1-921A-006097DF5BD4}", "{91956D21-9276-11d1-921A-006097DF5BD4}"); CreateFolderDisguise(szCurrDir, "{6756A641-DE71-11d0-831B-00AA005B4383}", "{6756A641-DE71-11d0-831B-00AA005B4383}"); CreateFolderDisguise(szCurrDir, "{F8383852-FCD3-11d1-A6B9-006097DF5BD4}", "{F8383852-FCD3-11d1-A6B9-006097DF5BD4}"); CreateFolderDisguise(szCurrDir, "{EBBC7C04-315E-11d2-B62F-006097DF5BD4}", "{EBBC7C04-315E-11d2-B62F-006097DF5BD4}"); CreateFolderDisguise(szCurrDir, "{75048700-EF1F-11D0-9888-006097DEACF9}", "{75048700-EF1F-11D0-9888-006097DEACF9}"); CreateFolderDisguise(szCurrDir, "{F490EB00-1240-11D1-9888-006097DEACF9}", "{F490EB00-1240-11D1-9888-006097DEACF9}"); CreateFolderDisguise(szCurrDir, "{52502EE0-EC80-11D0-89AB-00C04FC2972D}", "{52502EE0-EC80-11D0-89AB-00C04FC2972D}"); CreateFolderDisguise(szCurrDir, "{B22754E2-4574-11d1-9888-006097DEACF9}", "{B22754E2-4574-11d1-9888-006097DEACF9}"); CreateFolderDisguise(szCurrDir, "{74C26041-70D1-11d1-B75A-00A0C90564FE}", "{74C26041-70D1-11d1-B75A-00A0C90564FE}"); CreateFolderDisguise(szCurrDir, "{D2A105C0-87D5-11d1-8391-0000F80461CF}", "{D2A105C0-87D5-11d1-8391-0000F80461CF}"); CreateFolderDisguise(szCurrDir, "{a07034fd-6caa-4954-ac3f-97a27216f98a}", "{a07034fd-6caa-4954-ac3f-97a27216f98a}"); CreateFolderDisguise(szCurrDir, "{E8025004-1C42-11d2-BE2C-00A0C9A83DA1}", "{E8025004-1C42-11d2-BE2C-00A0C9A83DA1}"); CreateFolderDisguise(szCurrDir, "{24F14F01-7B1C-11d1-838f-0000F80461CF}", "{24F14F01-7B1C-11d1-838f-0000F80461CF}"); CreateFolderDisguise(szCurrDir, "{24F14F02-7B1C-11d1-838f-0000F80461CF}", "{24F14F02-7B1C-11d1-838f-0000F80461CF}"); CreateFolderDisguise(szCurrDir, "{0D2E74C4-3C34-11d2-A27E-00C04FC30871}", "{0D2E74C4-3C34-11d2-A27E-00C04FC30871}"); CreateFolderDisguise(szCurrDir, "{93A68750-951A-11d1-946F-000000000000}", "{93A68750-951A-11d1-946F-000000000000}"); CreateFolderDisguise(szCurrDir, "{FB700430-952C-11d1-946F-000000000000}", "{FB700430-952C-11d1-946F-000000000000}"); CreateFolderDisguise(szCurrDir, "{1E796980-9CC5-11D1-A83F-00C04FC99D61}", "{1E796980-9CC5-11D1-A83F-00C04FC99D61}"); CreateFolderDisguise(szCurrDir, "{178F34B8-A282-11d2-86C5-00C04F8EEA99}", "{178F34B8-A282-11d2-86C5-00C04F8EEA99}"); CreateFolderDisguise(szCurrDir, "{2CE4B5D8-A28F-11d2-86C5-00C04F8EEA99}", "{2CE4B5D8-A28F-11d2-86C5-00C04F8EEA99}"); CreateFolderDisguise(szCurrDir, "{CFCCC7A0-A282-11D1-9082-006008059382}", "{CFCCC7A0-A282-11D1-9082-006008059382}"); CreateFolderDisguise(szCurrDir, "{7057E952-BD1B-11d1-8919-00C04FC2C836}", "{7057E952-BD1B-11d1-8919-00C04FC2C836}"); CreateFolderDisguise(szCurrDir, "{93F2F68C-1D1B-11d3-A30E-00C04F79ABD1}", "{93F2F68C-1D1B-11d3-A30E-00C04F79ABD1}"); CreateFolderDisguise(szCurrDir, "{9B174B33-40FF-11d2-A27E-00C04FC30871}", "{9B174B33-40FF-11d2-A27E-00C04FC30871}"); CreateFolderDisguise(szCurrDir, "{328D8B21-7729-4bfc-954C-902B329D56B0}", "{328D8B21-7729-4bfc-954C-902B329D56B0}"); CreateFolderDisguise(szCurrDir, "{9B174B34-40FF-11d2-A27E-00C04FC30871}", "{9B174B34-40FF-11d2-A27E-00C04FC30871}"); CreateFolderDisguise(szCurrDir, "{F2275480-F782-4291-BD94-F13693513AEC}", "{F2275480-F782-4291-BD94-F13693513AEC}"); CreateFolderDisguise(szCurrDir, "{56A3372E-CE9C-11d2-9F0E-006097C686F6}", "{56A3372E-CE9C-11d2-9F0E-006097C686F6}"); CreateFolderDisguise(szCurrDir, "{AEAC19E4-89AE-4508-B9B7-BB867ABEE2ED}", "{AEAC19E4-89AE-4508-B9B7-BB867ABEE2ED}"); CreateFolderDisguise(szCurrDir, "{305CA226-D286-468e-B848-2B2E8E697B74}", "{305CA226-D286-468e-B848-2B2E8E697B74}"); CreateFolderDisguise(szCurrDir, "{9B174B35-40FF-11d2-A27E-00C04FC30871}", "{9B174B35-40FF-11d2-A27E-00C04FC30871}"); CreateFolderDisguise(szCurrDir, "{D8C3986F-813B-449c-845D-87B95D674ADE}", "{D8C3986F-813B-449c-845D-87B95D674ADE}"); CreateFolderDisguise(szCurrDir, "{B9B4B3FC-2B51-4a42-B5D8-324146AFCF25}", "{B9B4B3FC-2B51-4a42-B5D8-324146AFCF25}"); CreateFolderDisguise(szCurrDir, "{0E700BE1-9DB6-11d1-A1CE-00C04FD75D13}", "{0E700BE1-9DB6-11d1-A1CE-00C04FD75D13}"); CreateFolderDisguise(szCurrDir, "{12518493-00B2-11d2-9FA5-9E3420524153}", "{12518493-00B2-11d2-9FA5-9E3420524153}"); CreateFolderDisguise(szCurrDir, "{FFB8655F-81B9-4fce-B89C-9A6BA76D13E7}", "{FFB8655F-81B9-4fce-B89C-9A6BA76D13E7}"); CreateFolderDisguise(szCurrDir, "{12518492-00B2-11d2-9FA5-9E3420524153}", "{12518492-00B2-11d2-9FA5-9E3420524153}"); CreateFolderDisguise(szCurrDir, "{4657278A-411B-11d2-839A-00C04FD918D0}", "{4657278A-411B-11d2-839A-00C04FD918D0}"); CreateFolderDisguise(szCurrDir, "{4657278B-411B-11d2-839A-00C04FD918D0}", "{4657278B-411B-11d2-839A-00C04FD918D0}"); CreateFolderDisguise(szCurrDir, "{DE5BF786-477A-11d2-839D-00C04FD918D0}", "{DE5BF786-477A-11d2-839D-00C04FD918D0}"); CreateFolderDisguise(szCurrDir, "{3050f3BB-98b5-11cf-bb82-00aa00bdce0b}", "{3050f3BB-98b5-11cf-bb82-00aa00bdce0b}"); CreateFolderDisguise(szCurrDir, "{3050f3B3-98b5-11cf-bb82-00aa00bdce0b}", "{3050f3B3-98b5-11cf-bb82-00aa00bdce0b}"); CreateFolderDisguise(szCurrDir, "{3050f3B4-98b5-11cf-bb82-00aa00bdce0b}", "{3050f3B4-98b5-11cf-bb82-00aa00bdce0b}"); CreateFolderDisguise(szCurrDir, "{01E18D10-4D8B-11d2-855D-006008059367}", "{01E18D10-4D8B-11d2-855D-006008059367}"); CreateFolderDisguise(szCurrDir, "{49E1B500-4636-11d3-97F7-00C04F45D0B3}", "{49E1B500-4636-11d3-97F7-00C04F45D0B3}"); CreateFolderDisguise(szCurrDir, "{889A935D-971E-4B12-B90C-24DFC9E1E5E8}", "{889A935D-971E-4B12-B90C-24DFC9E1E5E8}"); CreateFolderDisguise(szCurrDir, "{FEF10FA2-355E-4e06-9381-9B24D7F7CC88}", "{FEF10FA2-355E-4e06-9381-9B24D7F7CC88}"); CreateFolderDisguise(szCurrDir, "{53C74826-AB99-4d33-ACA4-3117F51D3788}", "{53C74826-AB99-4d33-ACA4-3117F51D3788}"); CreateFolderDisguise(szCurrDir, "{D969A300-E7FF-11d0-A93B-00A0C90F2719}", "{D969A300-E7FF-11d0-A93B-00A0C90F2719}"); CreateFolderDisguise(szCurrDir, "{1CEBB3AB-7C10-499a-A417-92CA16C4CB83}", "{1CEBB3AB-7C10-499a-A417-92CA16C4CB83}"); CreateFolderDisguise(szCurrDir, "{4621A4E3-F0D6-4773-8A9C-46E77B174840}", "{4621A4E3-F0D6-4773-8A9C-46E77B174840}"); CreateFolderDisguise(szCurrDir, "{faadfc40-b777-4b69-aa81-77035ef0e6e8}", "{faadfc40-b777-4b69-aa81-77035ef0e6e8}"); CreateFolderDisguise(szCurrDir, "{0E5CBF21-D15F-11d0-8301-00AA005B4383}", "{0E5CBF21-D15F-11d0-8301-00AA005B4383}"); CreateFolderDisguise(szCurrDir, "{6D5313C0-8C62-11D1-B2CD-006097DF8C11}", "{6D5313C0-8C62-11D1-B2CD-006097DF8C11}"); CreateFolderDisguise(szCurrDir, "{165EBAF4-6D51-11d2-83AD-00C04FD918D0}", "{165EBAF4-6D51-11d2-83AD-00C04FD918D0}"); CreateFolderDisguise(szCurrDir, "{A6C17EB4-2D65-11d2-838F-00C04FD918D0}", "{A6C17EB4-2D65-11d2-838F-00C04FD918D0}"); CreateFolderDisguise(szCurrDir, "{5C9F0A12-959E-11d0-A3A4-00A0C9082636}", "{5C9F0A12-959E-11d0-A3A4-00A0C9082636}"); CreateFolderDisguise(szCurrDir, "{40B96610-B522-11d1-B3B4-00AA006EFDE7}", "{40B96610-B522-11d1-B3B4-00AA006EFDE7}"); CreateFolderDisguise(szCurrDir, "{596A9A94-013E-11d1-8D34-00A0C90F2719}", "{596A9A94-013E-11d1-8D34-00A0C90F2719}"); CreateFolderDisguise(szCurrDir, "{E13EF4E4-D2F2-11d0-9816-00C04FD91972}", "{E13EF4E4-D2F2-11d0-9816-00C04FD91972}"); CreateFolderDisguise(szCurrDir, "{80F30233-B7DF-11d2-A33B-006097DF5BD4}", "{80F30233-B7DF-11d2-A33B-006097DF5BD4}"); */
return 0; }
|