|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Prerequisites |
Windows Vista. |
|
Windows Vista has introduced a new mechanism to access what had previously been known as "special folders" since Windows 95 - under Vista they are called "Known Folders". Together with the change to what these folders are called, Microsoft also defined new APIs together with a new set of expanded constants based not on Long values, as was the case with CSIDL_x constants used to access these folders under pre-Vista versions of Windows, but rather based on GUIDs. Arguably under the hood, when passing one of the old CSIDL constants to a function such as SHGetFolderPath or SHGetSpecialFolder, previous versions of Windows were re-mapping the CSIDL long values to internal tables of GUIDs prior to pulling back the path as a result of the call. Now the GUIDs are exposed, and as future pages will show this is a Good Thing™ as it lets developers create (and remove) their own Known Folders through APIs to register and unregister these custom known folders. But more on that another time. Because the known folders are GUIDs, as shown in the third column in the illustration, APIs to manage GUIDs are required because how they look, and how then need to be mapped to GUID UDTs, is not a straightforward assignment. The const value of a Known Folder ID is represented as a string; a GUID is a four-member UDT comprised of 11 different integers, longs and bytes in a very specific order (and of course, it would be too easy if they were in the same order as the GUID strings themselves). In order to get GUID strings assigned to the correct GUID UDT members I have seen numerous VB pages that do back flips to utilize complex Mid$, CBye conversion, &H appending, and byte-assignments in order to change the order of those portions of a GUID string to the correct values and positions for assignment to the actual GUID UDT. Thankfully you won't find that mumbo-jumbo here - I like things easy. Under Vista, you can continue to use CSIDL values and the pre-vista Best Practice of calling SHGetFolderPath or the older SHGetSpecialFolder APIs, as both are remapped by Vista to call SHGetKnownFolder anyway. And, if you develop apps that need to support a wider variety of OS versions besides Vista, continuing using CSIDL values and the older APIs is the supported way to go. Just recognize that these old methods in Vista (or later) will negate the ability to use some of the enhanced Known Folder functionality Vista provides. This is a straightforward demo - a list box and a label for the result are all that is required. Form load code sets up the list columns for you. What I did not use in this demo are the actual Consts defined below; once I had the demo's load event coded to populate the listbox in order to show the GUID string data, I realised it was easier to just split out the values from each list line when selected and pass that GUID string to the routine that calls SHGetKnownFolder, so that's what I've done. But the Consts themselves can be used by developers who want or need to hard-code only a few of the FOLDERID values. One final word - note that like the older CSIDL methods, some GUIDs still point to virtual, rather than physical, folders on the system and thus for those values, no file system string is returned. |
BAS Module Code |
None. |
|
Form Code |
To a project form add a text box (Text1) and a Listbox (List1) along with the following code: |
|
Option Explicit '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved. ' Some pages may also contain other copyrights by the author. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Distribution: You can freely use this code in your own ' applications, but you may not reproduce ' or publish this code on any web site, ' online service, or distribute as source ' on any media without express permission. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'KNOWNFOLDER IDs Private Const FOLDERID_NetworkFolder = "{D20BEEC4-5CA8-4905-AE3B-BF251EA09B53}" Private Const FOLDERID_ComputerFolder = "{0AC0837C-BBF8-452A-850D-79D08E667CA7}" Private Const FOLDERID_InternetFolder = "{4D9F7874-4E0C-4904-967B-40B0D20C3E4B}" Private Const FOLDERID_ControlPanelFolder = "{82A74AEB-AEB4-465C-A014-D097EE346D63}" Private Const FOLDERID_PrintersFolder = "{76FC4E2D-D6AD-4519-A663-37BD56068185}" Private Const FOLDERID_SyncManagerFolder = "{43668BF8-C14E-49B2-97C9-747784D784B7}" Private Const FOLDERID_SyncSetupFolder = "{0F214138-B1D3-4a90-BBA9-27CBC0C5389A}" Private Const FOLDERID_ConflictFolder = "{4bfefb45-347d-4006-a5be-ac0cb0567192}" Private Const FOLDERID_SyncResultsFolder = "{289a9a43-be44-4057-a41b-587a76d7e7f9}" Private Const FOLDERID_RecycleBinFolder = "{B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC}" Private Const FOLDERID_ConnectionsFolder = "{6F0CD92B-2E97-45D1-88FF-B0D186B8DEDD}" Private Const FOLDERID_Fonts = "{FD228CB7-AE11-4AE3-864C-16F3910AB8FE}" Private Const FOLDERID_Desktop = "{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}" Private Const FOLDERID_Startup = "{B97D20BB-F46A-4C97-BA10-5E3608430854}" Private Const FOLDERID_Programs = "{A77F5D77-2E2B-44C3-A6A2-ABA601054A51}" Private Const FOLDERID_StartMenu = "{625B53C3-AB48-4EC1-BA1F-A1EF4146FC19}" Private Const FOLDERID_Recent = "{AE50C081-EBD2-438A-8655-8A092E34987A}" Private Const FOLDERID_SendTo = "{8983036C-27C0-404B-8F08-102D10DCFD74}" Private Const FOLDERID_Documents = "{FDD39AD0-238F-46AF-ADB4-6C85480369C7}" Private Const FOLDERID_Favorites = "{1777F761-68AD-4D8A-87BD-30B759FA33DD}" Private Const FOLDERID_NetHood = "{C5ABBF53-E17F-4121-8900-86626FC2C973}" Private Const FOLDERID_PrintHood = "{9274BD8D-CFD1-41C3-B35E-B13F55A758F4}" Private Const FOLDERID_Templates = "{A63293E8-664E-48DB-A079-DF759E0509F7}" Private Const FOLDERID_CommonStartup = "{82A5EA35-D9CD-47C5-9629-E15D2F714E6E}" Private Const FOLDERID_CommonPrograms = "{0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8}" Private Const FOLDERID_CommonStartMenu = "{A4115719-D62E-491D-AA7C-E74B8BE3B067}" Private Const FOLDERID_PublicDesktop = "{C4AA340D-F20F-4863-AFEF-F87EF2E6BA25}" Private Const FOLDERID_ProgramData = "{62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}" Private Const FOLDERID_CommonTemplates = "{B94237E7-57AC-4347-9151-B08C6C32D1F7}" Private Const FOLDERID_PublicDocuments = "{ED4824AF-DCE4-45A8-81E2-FC7965083634}" Private Const FOLDERID_RoamingAppData = "{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}" Private Const FOLDERID_LocalAppData = "{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}" Private Const FOLDERID_LocalAppDataLow = "{A520A1A4-1780-4FF6-BD18-167343C5AF16}" Private Const FOLDERID_InternetCache = "{352481E8-33BE-4251-BA85-6007CAEDCF9D}" Private Const FOLDERID_Cookies = "{2B0F765D-C0E9-4171-908E-08A611B84FF6}" Private Const FOLDERID_History = "{D9DC8A3B-B784-432E-A781-5A1130A75963}" Private Const FOLDERID_System = "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}" Private Const FOLDERID_SystemX86 = "{D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27}" Private Const FOLDERID_Windows = "{F38BF404-1D43-42F2-9305-67DE0B28FC23}" Private Const FOLDERID_Profile = "{5E6C858F-0E22-4760-9AFE-EA3317B67173}" Private Const FOLDERID_Pictures = "{33E28130-4E1E-4676-835A-98395C3BC3BB}" Private Const FOLDERID_ProgramFilesX86 = "{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}" Private Const FOLDERID_ProgramFilesCommonX86 = "{DE974D24-D9C6-4D3E-BF91-F4455120B917}" Private Const FOLDERID_ProgramFilesX64 = "{6D809377-6AF0-444b-8957-A3773F02200E}" Private Const FOLDERID_ProgramFilesCommonX64 = "{6365D5A7-0F0D-45e5-87F6-0DA56B6A4F7D}" Private Const FOLDERID_ProgramFiles = "{905e63b6-c1bf-494e-b29c-65b732d3d21a}" Private Const FOLDERID_ProgramFilesCommon = "{F7F1ED05-9F6D-47A2-AAAE-29D317C6F066}" Private Const FOLDERID_AdminTools = "{724EF170-A42D-4FEF-9F26-B60E846FBA4F}" Private Const FOLDERID_CommonAdminTools = "{D0384E7D-BAC3-4797-8F14-CBA229B392B5}" Private Const FOLDERID_Music = "{4BD8D571-6D19-48D3-BE97-422220080E43}" Private Const FOLDERID_Videos = "{18989B1D-99B5-455B-841C-AB7C74E4DDFC}" Private Const FOLDERID_PublicPictures = "{B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5}" Private Const FOLDERID_PublicMusic = "{3214FAB5-9757-4298-BB61-92A9DEAA44FF}" Private Const FOLDERID_PublicVideos = "{2400183A-6185-49FB-A2D8-4A392A602BA3}" Private Const FOLDERID_ResourceDir = "{8AD10C31-2ADB-4296-A8F7-E4701232C972}" Private Const FOLDERID_LocalizedResourcesDir = "{2A00375E-224C-49DE-B8D1-440DF7EF3DDC}" Private Const FOLDERID_CommonOEMLinks = "{C1BAE2D0-10DF-4334-BEDD-7AA20B227A9D}" Private Const FOLDERID_CDBurning = "{9E52AB10-F80D-49DF-ACB8-4330F5687855}" Private Const FOLDERID_UserProfiles = "{0762D272-C50A-4BB0-A382-697DCD729B80}" Private Const FOLDERID_Playlists = "{DE92C1C7-837F-4F69-A3BB-86E631204A23}" Private Const FOLDERID_SamplePlaylists = "{15CA69B3-30EE-49C1-ACE1-6B5EC372AFB5}" Private Const FOLDERID_SampleMusic = "{B250C668-F57D-4EE1-A63C-290EE7D1AA1F}" Private Const FOLDERID_SamplePictures = "{C4900540-2379-4C75-844B-64E6FAF8716B}" Private Const FOLDERID_SampleVideos = "{859EAD94-2E85-48AD-A71A-0969CB56A6CD}" Private Const FOLDERID_PhotoAlbums = "{69D2CF90-FC33-4FB7-9A0C-EBB0F0FCB43C}" Private Const FOLDERID_Public = "{DFDF76A2-C82A-4D63-906A-5644AC457385}" Private Const FOLDERID_ChangeRemovePrograms = "{df7266ac-9274-4867-8d55-3bd661de872d}" Private Const FOLDERID_AppUpdates = "{a305ce99-f527-492b-8b1a-7e76fa98d6e4}" Private Const FOLDERID_AddNewPrograms = "{de61d971-5ebc-4f02-a3a9-6c82895e5c04}" Private Const FOLDERID_Downloads = "{374DE290-123F-4565-9164-39C4925E467B}" Private Const FOLDERID_PublicDownloads = "{3D644C9B-1FB8-4f30-9B45-F670235F79C0}" Private Const FOLDERID_SavedSearches = "{7d1d3a04-debb-4115-95cf-2f29da2920da}" Private Const FOLDERID_QuickLaunch = "{52a4f021-7b75-48a9-9f6b-4b87a210bc8f}" Private Const FOLDERID_Contacts = "{56784854-C6CB-462b-8169-88E350ACB882}" Private Const FOLDERID_SidebarParts = "{A75D362E-50FC-4fb7-AC2C-A8BEAA314493}" Private Const FOLDERID_SidebarDefaultParts = "{7B396E54-9EC5-4300-BE0A-2482EBAE1A26}" Private Const FOLDERID_TreeProperties = "{5b3749ad-b49f-49c1-83eb-15370fbd4882}" Private Const FOLDERID_PublicGameTasks = "{DEBF2536-E1A8-4c59-B6A2-414586476AEA}" Private Const FOLDERID_GameTasks = "{054FAE61-4DD8-4787-80B6-090220C4B700}" Private Const FOLDERID_SavedGames = "{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}" Private Const FOLDERID_Games = "{CAC52C1A-B53D-4edc-92D7-6B2E8AC19434}" Private Const FOLDERID_RecordedTV = "{bd85e001-112e-431e-983b-7b15ac09fff1}" Private Const FOLDERID_SEARCH_MAPI = "{98ec0e18-2098-4d44-8644-66979315a281}" Private Const FOLDERID_SEARCH_CSC = "{ee32e446-31ca-4aba-814f-a5ebd2fd6d5e}" Private Const FOLDERID_Links = "{bfb9d5e0-c6a9-404c-b2b2-ae6db6af4968}" Private Const FOLDERID_UsersFiles = "{f3ce0f7c-4901-4acc-8648-d5d44b04ef8f}" Private Const FOLDERID_SearchHome = "{190337d1-b8ca-4121-a639-6d472d16972a}" Private Const FOLDERID_OriginalImages = "{2C36C0AA-5812-4b87-BFD0-4CD0DFB19B39}" Private Type GUID Data1 As Long Data2 As Integer Data3 As Integer Data4(7) As Byte End Type Private Declare Function SHGetKnownFolderPath Lib "shell32" _ (rfid As Any, _ ByVal dwFlags As Long, _ ByVal hToken As Long, _ ppszPath As Long) As Long Private Declare Function CLSIDFromString Lib "ole32" _ (ByVal lpszGuid As Long, _ pGuid As Any) As Long Private Declare Sub CopyMemory Lib "kernel32" _ Alias "RtlMoveMemory" _ (pDest As Any, _ pSrc As Any, _ ByVal ByteLen As Long) Private Declare Sub CoTaskMemFree Lib "ole32" (ByVal hMem As Long) Private Declare Function lstrlenW Lib "kernel32" (ByVal ptr As Long) As Long 'needed for list columns Private Const LB_SETTABSTOPS As Long = &H192 Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Sub Form_Load() Dim vTab As String vTab = Chr$(9) 'a little listbox column setup ReDim TabArray(0 To 1) As Long TabArray(0) = 157 TabArray(1) = 381 Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 0&, ByVal 0&) Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 2&, TabArray(0)) With List1 .AddItem "FOLDERID_NetworkFolder" & _ vTab & "CSIDL_NETWORK, CSIDL_COMPUTERSNEARME" & _ vTab & "{D20BEEC4-5CA8-4905-AE3B-BF251EA09B53}" .AddItem "FOLDERID_ComputerFolder" & _ vTab & "CSIDL_DRIVES" & _ vTab & "{0AC0837C-BBF8-452A-850D-79D08E667CA7}" .AddItem "FOLDERID_InternetFolder" & _ vTab & "CSIDL_INTERNET" & _ vTab & "{4D9F7874-4E0C-4904-967B-40B0D20C3E4B}" .AddItem "FOLDERID_ControlPanelFolder" & _ vTab & "CSIDL_CONTROLS" & _ vTab & "{82A74AEB-AEB4-465C-A014-D097EE346D63}" .AddItem "FOLDERID_PrintersFolder" & _ vTab & "CSIDL_PRINTERS" & _ vTab & "{76FC4E2D-D6AD-4519-A663-37BD56068185}" .AddItem "FOLDERID_SyncManagerFolder" & _ vTab & "None, new in Windows Vista" & _ vTab & "{43668BF8-C14E-49B2-97C9-747784D784B7}" .AddItem "FOLDERID_SyncSetupFolder" & _ vTab & "None, new in Windows Vista" & _ vTab & "{0F214138-B1D3-4a90-BBA9-27CBC0C5389A}" .AddItem "FOLDERID_ConflictFolder" & _ vTab & "None, new in Windows Vista" & _ vTab & "{4bfefb45-347d-4006-a5be-ac0cb0567192}" .AddItem "FOLDERID_SyncResultsFolder" & _ vTab & "None, new in Windows Vista" & _ vTab & "{289a9a43-be44-4057-a41b-587a76d7e7f9}" .AddItem "FOLDERID_RecycleBinFolder" & _ vTab & "CSIDL_BITBUCKET" & _ vTab & "{B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC}" .AddItem "FOLDERID_ConnectionsFolder" & _ vTab & "CSIDL_CONNECTIONS" & _ vTab & "{6F0CD92B-2E97-45D1-88FF-B0D186B8DEDD}" .AddItem "FOLDERID_Fonts" & _ vTab & "CSIDL_CONNECTIONS" & _ vTab & "{FD228CB7-AE11-4AE3-864C-16F3910AB8FE}" .AddItem "FOLDERID_Desktop" & _ vTab & "CSIDL_DESKTOP, CSIDL_DESKTOPDIRECTORY" & _ vTab & "{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}" .AddItem "FOLDERID_Startup" & _ vTab & "CSIDL_STARTUP, CSIDL_ALTSTARTUP" & _ vTab & "{B97D20BB-F46A-4C97-BA10-5E3608430854}" .AddItem "FOLDERID_Programs" & _ vTab & "CSIDL_PROGRAMS" & _ vTab & "{A77F5D77-2E2B-44C3-A6A2-ABA601054A51}" .AddItem "FOLDERID_StartMenu" & _ vTab & "CSIDL_STARTMENU" & _ vTab & "{625B53C3-AB48-4EC1-BA1F-A1EF4146FC19}" .AddItem "FOLDERID_Recent" & _ vTab & "CSIDL_RECENT" & _ vTab & "{AE50C081-EBD2-438A-8655-8A092E34987A}" .AddItem "FOLDERID_SendTo" & _ vTab & "CSIDL_SENDTO" & _ vTab & "{8983036C-27C0-404B-8F08-102D10DCFD74}" .AddItem "FOLDERID_Documents" & _ vTab & "CSIDL_MYDOCUMENTS, CSIDL_PERSONAL" & _ vTab & "{FDD39AD0-238F-46AF-ADB4-6C85480369C7}" .AddItem "FOLDERID_Favorites" & _ vTab & "CSIDL_FAVORITES, CSIDL_COMMON_FAVORITES" & _ vTab & "{1777F761-68AD-4D8A-87BD-30B759FA33DD}" .AddItem "FOLDERID_NetHood" & _ vTab & "CSIDL_NETHOOD" & _ vTab & "{C5ABBF53-E17F-4121-8900-86626FC2C973}" .AddItem "FOLDERID_PrintHood" & _ vTab & "CSIDL_PRINTHOOD" & _ vTab & "{9274BD8D-CFD1-41C3-B35E-B13F55A758F4}" .AddItem "FOLDERID_Templates" & _ vTab & "CSIDL_TEMPLATES" & _ vTab & "{A63293E8-664E-48DB-A079-DF759E0509F7}" .AddItem "FOLDERID_CommonStartup" & _ vTab & "CSIDL_COMMON_STARTUP, CSIDL_COMMON_ALTSTARTUP" & _ vTab & "{82A5EA35-D9CD-47C5-9629-E15D2F714E6E}" .AddItem "FOLDERID_CommonPrograms" & _ vTab & "CSIDL_COMMON_PROGRAMS" & _ vTab & "{0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8}" .AddItem "FOLDERID_CommonStartMenu" & _ vTab & "CSIDL_COMMON_STARTMENU" & _ vTab & "{A4115719-D62E-491D-AA7C-E74B8BE3B067}" .AddItem "FOLDERID_PublicDesktop" & _ vTab & "None, new in Windows Vista" & _ vTab & "{C4AA340D-F20F-4863-AFEF-F87EF2E6BA25}" .AddItem "FOLDERID_ProgramData" & _ vTab & "CSIDL_COMMON_APPDATA" & _ vTab & "{62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}" .AddItem "FOLDERID_CommonTemplates" & _ vTab & "CSIDL_COMMON_TEMPLATES" & _ vTab & "{B94237E7-57AC-4347-9151-B08C6C32D1F7}" .AddItem "FOLDERID_PublicDocuments" & _ vTab & "CSIDL_COMMON_DOCUMENTS" & _ vTab & "{ED4824AF-DCE4-45A8-81E2-FC7965083634}" .AddItem "FOLDERID_RoamingAppData" & _ vTab & "CSIDL_APPDATA" & _ vTab & "{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}" .AddItem "FOLDERID_LocalAppData" & _ vTab & "CSIDL_LOCAL_APPDATA" & _ vTab & "{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}" .AddItem "FOLDERID_LocalAppDataLow" & _ vTab & "None, new in Windows Vista" & _ vTab & "{A520A1A4-1780-4FF6-BD18-167343C5AF16}" .AddItem "FOLDERID_InternetCache" & _ vTab & "CSIDL_INTERNET_CACHE" & _ vTab & "{352481E8-33BE-4251-BA85-6007CAEDCF9D}" .AddItem "FOLDERID_Cookies" & _ vTab & "CSIDL_COOKIES" & _ vTab & "{2B0F765D-C0E9-4171-908E-08A611B84FF6}" .AddItem "FOLDERID_History" & _ vTab & "CSIDL_HISTORY" & _ vTab & "{D9DC8A3B-B784-432E-A781-5A1130A75963}" .AddItem "FOLDERID_System" & _ vTab & "CSIDL_SYSTEM" & _ vTab & "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}" .AddItem "FOLDERID_SystemX86" & _ vTab & "CSIDL_SYSTEMX86" & _ vTab & "{D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27}" .AddItem "FOLDERID_Windows" & _ vTab & "CSIDL_WINDOWS" & _ vTab & "{F38BF404-1D43-42F2-9305-67DE0B28FC23}" .AddItem "FOLDERID_Profile" & _ vTab & "CSIDL_PROFILE" & _ vTab & "{5E6C858F-0E22-4760-9AFE-EA3317B67173}" .AddItem "FOLDERID_Pictures" & _ vTab & "CSIDL_MYPICTURES" & _ vTab & "{33E28130-4E1E-4676-835A-98395C3BC3BB}" .AddItem "FOLDERID_ProgramFilesX86" & _ vTab & "CSIDL_PROGRAM_FILESX86" & _ vTab & "{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}" .AddItem "FOLDERID_ProgramFilesCommonX86" & _ vTab & "CSIDL_PROGRAM_FILES_COMMONX86" & _ vTab & "{DE974D24-D9C6-4D3E-BF91-F4455120B917}" .AddItem "FOLDERID_ProgramFilesX64" & _ vTab & "Not applicable" & _ vTab & "{6D809377-6AF0-444b-8957-A3773F02200E}" .AddItem "FOLDERID_ProgramFilesCommonX64" & _ vTab & "Not applicable" & _ vTab & "{6365D5A7-0F0D-45e5-87F6-0DA56B6A4F7D}" .AddItem "FOLDERID_ProgramFiles" & _ vTab & "CSIDL_PROGRAM_FILES" & _ vTab & "{905e63b6-c1bf-494e-b29c-65b732d3d21a}" .AddItem "FOLDERID_ProgramFilesCommon" & _ vTab & "CSIDL_PROGRAM_FILES_COMMON" & _ vTab & "{F7F1ED05-9F6D-47A2-AAAE-29D317C6F066}" .AddItem "FOLDERID_AdminTools" & _ vTab & "CSIDL_ADMINTOOLS" & _ vTab & "{724EF170-A42D-4FEF-9F26-B60E846FBA4F}" .AddItem "FOLDERID_CommonAdminTools" & _ vTab & "CSIDL_COMMON_ADMINTOOLS" & _ vTab & "{D0384E7D-BAC3-4797-8F14-CBA229B392B5}" .AddItem "FOLDERID_Music" & _ vTab & "CSIDL_MYMUSIC" & _ vTab & "{4BD8D571-6D19-48D3-BE97-422220080E43}" .AddItem "FOLDERID_Videos" & _ vTab & "CSIDL_MYVIDEO" & _ vTab & "{18989B1D-99B5-455B-841C-AB7C74E4DDFC}" .AddItem "FOLDERID_PublicPictures" & _ vTab & "CSIDL_COMMON_PICTURES" & _ vTab & "{B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5}" .AddItem "FOLDERID_PublicMusic" & _ vTab & "CSIDL_COMMON_MUSIC" & _ vTab & "{3214FAB5-9757-4298-BB61-92A9DEAA44FF}" .AddItem "FOLDERID_PublicVideos" & _ vTab & "CSIDL_COMMON_VIDEO" & _ vTab & "{2400183A-6185-49FB-A2D8-4A392A602BA3}" .AddItem "FOLDERID_ResourceDir" & _ vTab & "CSIDL_RESOURCES" & _ vTab & "{8AD10C31-2ADB-4296-A8F7-E4701232C972}" .AddItem "FOLDERID_LocalizedResourcesDir" & _ vTab & "CSIDL_RESOURCES_LOCALIZED" & _ vTab & "{2A00375E-224C-49DE-B8D1-440DF7EF3DDC}" .AddItem "FOLDERID_CommonOEMLinks" & _ vTab & "CSIDL_COMMON_OEM_LINKS" & _ vTab & "{C1BAE2D0-10DF-4334-BEDD-7AA20B227A9D}" .AddItem "FOLDERID_CDBurning" & _ vTab & "CSIDL_CDBURN_AREA" & _ vTab & "{9E52AB10-F80D-49DF-ACB8-4330F5687855}" .AddItem "FOLDERID_UserProfiles" & _ vTab & "None, new in Windows Vista" & _ vTab & "{0762D272-C50A-4BB0-A382-697DCD729B80}" .AddItem "FOLDERID_Playlists" & _ vTab & "None, new in Windows Vista" & _ vTab & "{DE92C1C7-837F-4F69-A3BB-86E631204A23}" .AddItem "FOLDERID_SamplePlaylists" & _ vTab & "None, new in Windows Vista" & _ vTab & "{15CA69B3-30EE-49C1-ACE1-6B5EC372AFB5}" .AddItem "FOLDERID_SampleMusic" & _ vTab & "None, new in Windows Vista" & _ vTab & "{B250C668-F57D-4EE1-A63C-290EE7D1AA1F}" .AddItem "FOLDERID_SamplePictures" & _ vTab & "None, new in Windows Vista" & _ vTab & "{C4900540-2379-4C75-844B-64E6FAF8716B}" .AddItem "FOLDERID_SampleVideos" & _ vTab & "None, new in Windows Vista" & _ vTab & "{859EAD94-2E85-48AD-A71A-0969CB56A6CD}" .AddItem "FOLDERID_PhotoAlbums" & _ vTab & "None, new in Windows Vista" & _ vTab & "{69D2CF90-FC33-4FB7-9A0C-EBB0F0FCB43C}" .AddItem "FOLDERID_Public" & _ vTab & "None, new in Windows Vista" & _ vTab & "{DFDF76A2-C82A-4D63-906A-5644AC457385}" .AddItem "FOLDERID_ChangeRemovePrograms" & _ vTab & "None, new in Windows Vista" & _ vTab & "{df7266ac-9274-4867-8d55-3bd661de872d}" .AddItem "FOLDERID_AppUpdates" & _ vTab & "None, new in Windows Vista" & _ vTab & "{a305ce99-f527-492b-8b1a-7e76fa98d6e4}" .AddItem "FOLDERID_AddNewPrograms" & _ vTab & "None, new in Windows Vista" & _ vTab & "{de61d971-5ebc-4f02-a3a9-6c82895e5c04}" .AddItem "FOLDERID_Downloads" & _ vTab & "None, new in Windows Vista" & _ vTab & "{374DE290-123F-4565-9164-39C4925E467B}" .AddItem "FOLDERID_PublicDownloads" & _ vTab & "None, new in Windows Vista" & _ vTab & "{3D644C9B-1FB8-4f30-9B45-F670235F79C0}" .AddItem "FOLDERID_SavedSearches" & _ vTab & "None, new in Windows Vista" & _ vTab & "{7d1d3a04-debb-4115-95cf-2f29da2920da}" .AddItem "FOLDERID_QuickLaunch" & _ vTab & "None, new in Windows Vista" & _ vTab & "{52a4f021-7b75-48a9-9f6b-4b87a210bc8f}" .AddItem "FOLDERID_Contacts" & _ vTab & "None, new in Windows Vista" & _ vTab & "{56784854-C6CB-462b-8169-88E350ACB882}" .AddItem "FOLDERID_SidebarParts" & _ vTab & "None, new in Windows Vista" & _ vTab & "{A75D362E-50FC-4fb7-AC2C-A8BEAA314493}" .AddItem "FOLDERID_SidebarDefaultParts" & _ vTab & "None, new in Windows Vista" & _ vTab & "{7B396E54-9EC5-4300-BE0A-2482EBAE1A26}" .AddItem "FOLDERID_TreeProperties" & _ vTab & "None, new in Windows Vista" & _ vTab & "{5b3749ad-b49f-49c1-83eb-15370fbd4882}" .AddItem "FOLDERID_PublicGameTasks" & _ vTab & "None, new in Windows Vista" & _ vTab & "{DEBF2536-E1A8-4c59-B6A2-414586476AEA}" .AddItem "FOLDERID_GameTasks" & _ vTab & "None, new in Windows Vista" & _ vTab & "{054FAE61-4DD8-4787-80B6-090220C4B700}" .AddItem "FOLDERID_SavedGames" & _ vTab & "None, new in Windows Vista" & _ vTab & "{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}" .AddItem "FOLDERID_Games" & _ vTab & "None, new in Windows Vista" & _ vTab & "{CAC52C1A-B53D-4edc-92D7-6B2E8AC19434}" .AddItem "FOLDERID_RecordedTV" & _ vTab & "None, new in Windows Vista" & _ vTab & "{bd85e001-112e-431e-983b-7b15ac09fff1}" .AddItem "FOLDERID_SEARCH_MAPI" & _ vTab & "None, new in Windows Vista" & _ vTab & "{98ec0e18-2098-4d44-8644-66979315a281}" .AddItem "FOLDERID_SEARCH_CSC" & _ vTab & "None, new in Windows Vista" & _ vTab & "{ee32e446-31ca-4aba-814f-a5ebd2fd6d5e}" .AddItem "FOLDERID_Links" & _ vTab & "None, new in Windows Vista" & _ vTab & "{bfb9d5e0-c6a9-404c-b2b2-ae6db6af4968}" .AddItem "FOLDERID_UsersFiles" & _ vTab & "None, new in Windows Vista" & _ vTab & "{f3ce0f7c-4901-4acc-8648-d5d44b04ef8f}" .AddItem "FOLDERID_SearchHome" & _ vTab & "None, new in Windows Vista" & _ vTab & "{190337d1-b8ca-4121-a639-6d472d16972a}" .AddItem "FOLDERID_OriginalImages" & _ vTab & "None, new in Windows Vista" & _ vTab & "{2C36C0AA-5812-4b87-BFD0-4CD0DFB19B39}" End With With Label1 .Caption = "" .Font.Bold = True .AutoSize = True End With End Sub Private Sub List1_Click() Dim a() As String Dim sFolder As String If List1.ListIndex > -1 Then 'split the list item on the tab character a() = Split(List1.List(List1.ListIndex), Chr$(9)) 'a(2) holds the third item - the GUID string sFolder = GetFolder(a(2)) If Len(sFolder) > 0 Then Label1.Caption = sFolder Else Label1.Caption = "Virtual Folder - no file path" End If End If End Sub Private Function GetFolder(sRfid) As String Dim ppszPath As Long Dim gGuid As GUID 'attempt to convert the knownfolder ID to a GUID If CLSIDFromString(StrPtr(sRfid), gGuid) = 0 Then 'pass gGuid to SHGetKnownFolderPath, which returns 'the path as a pointer to a Unicode string. If SHGetKnownFolderPath(gGuid, 0, 0, ppszPath) = 0 Then 'if no error on return get the path 'if present and release the pointer GetFolder = GetPointerToByteStringW(ppszPath) Call CoTaskMemFree(ppszPath) End If End If 'CLSIDFromString End Function Private Function GetPointerToByteStringW(ByVal dwData As Long) As String Dim tmp() As Byte Dim tmplen As Long If dwData <> 0 Then 'determine the size of the returned data tmplen = lstrlenW(dwData) * 2 If tmplen <> 0 Then 'create a byte buffer for the string 'then assign it to the return value 'of the function ReDim tmp(0 To (tmplen - 1)) As Byte CopyMemory tmp(0), ByVal dwData, tmplen GetPointerToByteStringW = tmp End If End If End Function |
Comments |
Run and select an item from the list. If the selected item represents a physical folder the path will be displayed in the label. Virtual folders never return a physical path. |
|
|
|
|||||
|
|||||
|
|||||
Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved. |