Windows 7 Special Folders
Windows 7 Special Folders
Windows 7 Special Folders
Windows 7 Special Folders
Windows 7 Special Folders
Windows 7 Special Folders Windows 7 Special Folders Windows 7 Special Folders Windows 7 Special Folders Windows 7 Special Folders Windows 7 Special Folders Windows 7 Special Folders Windows 7 Special Folders
Windows 7 Special Folders Windows 7 Special Folders
Windows 7 Special Folders
Go Back  Xtreme Visual Basic Talk > > > Windows 7 Special Folders

Thread Tools Display Modes
Old 06-24-2010, 01:44 AM
M84Speed M84Speed is offline
Join Date: Jun 2010
Posts: 2
Question Windows 7 Special Folders

Hi, I need to get and set special folders of Windows 7 with a Program (I'm using VB 2010)

As I know the usual way to do this is to use the environment class with the following Statement:
szPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Unfortunately this does not work for new known folders like "Contacts", "Links", "Saved Games", ...
After doing some research I found the API function "SHGetKnownFolderPath" which should do the job. Unfortunately I found not a single hint in the whole web how to use this function in VB 2010. Many ways are shown but even the declaration of the function itself is not shown properly. Does anyone know how this function is declared properly and how I have to feed it with the right datatypes....

Any help is very much appreciated.
Best M84Speed
Reply With Quote
Old 06-24-2010, 02:28 AM
PlausiblyDamp's Avatar
PlausiblyDampWindows 7 Special Folders PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058

You should also be able to use the COM IKnownFolder interface for this, not tried it personally but has some c# code that imports the IKnownFolder stuff (starts line 384) you might be able to pull the relevant sections out of that file and compile it into a c# dll you can use from your vb app.
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
Old 06-24-2010, 06:10 AM
M84Speed M84Speed is offline
Join Date: Jun 2010
Posts: 2

I solved it.
Here ist the code that works (in case someone needs this stuff):

Public NotInheritable Class KnownFolders
	   	Public Shared ReadOnly AddNewPrograms As New Guid("de61d971-5ebc-4f02-a3a9-6c82895e5c04")
	   	Public Shared ReadOnly AdminTools As New Guid("724EF170-A42D-4FEF-9F26-B60E846FBA4F")
	   	Public Shared ReadOnly AppUpdates As New Guid("a305ce99-f527-492b-8b1a-7e76fa98d6e4")
	   	Public Shared ReadOnly CDBurning As New Guid("9E52AB10-F80D-49DF-ACB8-4330F5687855")
	   	Public Shared ReadOnly ChangeRemovePrograms As New Guid("df7266ac-9274-4867-8d55-3bd661de872d")
	   	Public Shared ReadOnly CommonAdminTools As New Guid("D0384E7D-BAC3-4797-8F14-CBA229B392B5")
	   	Public Shared ReadOnly CommonOEMLinks As New Guid("C1BAE2D0-10DF-4334-BEDD-7AA20B227A9D")
	   	Public Shared ReadOnly CommonPrograms As New Guid("0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8")
	   	Public Shared ReadOnly CommonStartMenu As New Guid("A4115719-D62E-491D-AA7C-E74B8BE3B067")
	   	Public Shared ReadOnly CommonStartup As New Guid("82A5EA35-D9CD-47C5-9629-E15D2F714E6E")
	   	Public Shared ReadOnly CommonTemplates As New Guid("B94237E7-57AC-4347-9151-B08C6C32D1F7")
	   	Public Shared ReadOnly ComputerFolder As New Guid("0AC0837C-BBF8-452A-850D-79D08E667CA7")
	   	Public Shared ReadOnly ConflictFolder As New Guid("4bfefb45-347d-4006-a5be-ac0cb0567192")
	   	Public Shared ReadOnly ConnectionsFolder As New Guid("6F0CD92B-2E97-45D1-88FF-B0D186B8DEDD")
	   	Public Shared ReadOnly Contacts As New Guid("56784854-C6CB-462b-8169-88E350ACB882")
	   	Public Shared ReadOnly ControlPanelFolder As New Guid("82A74AEB-AEB4-465C-A014-D097EE346D63")
	   	Public Shared ReadOnly Cookies As New Guid("2B0F765D-C0E9-4171-908E-08A611B84FF6")
	   	Public Shared ReadOnly Desktop As New Guid("B4BFCC3A-DB2C-424C-B029-7FE99A87C641")
	   	Public Shared ReadOnly Documents As New Guid("FDD39AD0-238F-46AF-ADB4-6C85480369C7")
	   	Public Shared ReadOnly Downloads As New Guid("374DE290-123F-4565-9164-39C4925E467B")
	   	Public Shared ReadOnly Favorites As New Guid("1777F761-68AD-4D8A-87BD-30B759FA33DD")
	   	Public Shared ReadOnly Fonts As New Guid("FD228CB7-AE11-4AE3-864C-16F3910AB8FE")
	   	Public Shared ReadOnly Games As New Guid("CAC52C1A-B53D-4edc-92D7-6B2E8AC19434")
	   	Public Shared ReadOnly GameTasks As New Guid("054FAE61-4DD8-4787-80B6-090220C4B700")
	   	Public Shared ReadOnly History As New Guid("D9DC8A3B-B784-432E-A781-5A1130A75963")
	   	Public Shared ReadOnly InternetCache As New Guid("352481E8-33BE-4251-BA85-6007CAEDCF9D")
	   	Public Shared ReadOnly InternetFolder As New Guid("4D9F7874-4E0C-4904-967B-40B0D20C3E4B")
	   	Public Shared ReadOnly Links As New Guid("bfb9d5e0-c6a9-404c-b2b2-ae6db6af4968")
	   	Public Shared ReadOnly LocalAppData As New Guid("F1B32785-6FBA-4FCF-9D55-7B8E7F157091")
	   	Public Shared ReadOnly LocalAppDataLow As New Guid("A520A1A4-1780-4FF6-BD18-167343C5AF16")
	   	Public Shared ReadOnly LocalizedResourcesDir As New Guid("2A00375E-224C-49DE-B8D1-440DF7EF3DDC")
	   	Public Shared ReadOnly Music As New Guid("4BD8D571-6D19-48D3-BE97-422220080E43")
	   	Public Shared ReadOnly NetHood As New Guid("C5ABBF53-E17F-4121-8900-86626FC2C973")
	   	Public Shared ReadOnly NetworkFolder As New Guid("D20BEEC4-5CA8-4905-AE3B-BF251EA09B53")
	   	Public Shared ReadOnly OriginalImages As New Guid("2C36C0AA-5812-4b87-BFD0-4CD0DFB19B39")
	   	Public Shared ReadOnly PhotoAlbums As New Guid("69D2CF90-FC33-4FB7-9A0C-EBB0F0FCB43C")
	   	Public Shared ReadOnly Pictures As New Guid("33E28130-4E1E-4676-835A-98395C3BC3BB")
	   	Public Shared ReadOnly Playlists As New Guid("DE92C1C7-837F-4F69-A3BB-86E631204A23")
	   	Public Shared ReadOnly PrintersFolder As New Guid("76FC4E2D-D6AD-4519-A663-37BD56068185")
	   	Public Shared ReadOnly PrintHood As New Guid("9274BD8D-CFD1-41C3-B35E-B13F55A758F4")
	   	Public Shared ReadOnly Profile As New Guid("5E6C858F-0E22-4760-9AFE-EA3317B67173")
	   	Public Shared ReadOnly ProgramData As New Guid("62AB5D82-FDC1-4DC3-A9DD-070D1D495D97")
	   	Public Shared ReadOnly ProgramFiles As New Guid("905e63b6-c1bf-494e-b29c-65b732d3d21a")
	   	Public Shared ReadOnly ProgramFilesX64 As New Guid("6D809377-6AF0-444b-8957-A3773F02200E")
	   	Public Shared ReadOnly ProgramFilesX86 As New Guid("7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E")
	   	Public Shared ReadOnly ProgramFilesCommon As New Guid("F7F1ED05-9F6D-47A2-AAAE-29D317C6F066")
	   	Public Shared ReadOnly ProgramFilesCommonX64 As New Guid("6365D5A7-0F0D-45E5-87F6-0DA56B6A4F7D")
	   	Public Shared ReadOnly ProgramFilesCommonX86 As New Guid("DE974D24-D9C6-4D3E-BF91-F4455120B917")
	   	Public Shared ReadOnly Programs As New Guid("A77F5D77-2E2B-44C3-A6A2-ABA601054A51")
	   	Public Shared ReadOnly [Public] As New Guid("DFDF76A2-C82A-4D63-906A-5644AC457385")
	   	Public Shared ReadOnly PublicDesktop As New Guid("C4AA340D-F20F-4863-AFEF-F87EF2E6BA25")
	   	Public Shared ReadOnly PublicDocuments As New Guid("ED4824AF-DCE4-45A8-81E2-FC7965083634")
	   	Public Shared ReadOnly PublicDownloads As New Guid("3D644C9B-1FB8-4f30-9B45-F670235F79C0")
	   	Public Shared ReadOnly PublicGameTasks As New Guid("DEBF2536-E1A8-4c59-B6A2-414586476AEA")
	   	Public Shared ReadOnly PublicMusic As New Guid("3214FAB5-9757-4298-BB61-92A9DEAA44FF")
	   	Public Shared ReadOnly PublicPictures As New Guid("B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5")
	   	Public Shared ReadOnly PublicVideos As New Guid("2400183A-6185-49FB-A2D8-4A392A602BA3")
	   	Public Shared ReadOnly QuickLaunch As New Guid("52a4f021-7b75-48a9-9f6b-4b87a210bc8f")
	   	Public Shared ReadOnly Recent As New Guid("AE50C081-EBD2-438A-8655-8A092E34987A")
	   	Public Shared ReadOnly RecycleBinFolder As New Guid("B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC")
	   	Public Shared ReadOnly ResourceDir As New Guid("8AD10C31-2ADB-4296-A8F7-E4701232C972")
	   	Public Shared ReadOnly RoamingAppData As New Guid("3EB685DB-65F9-4CF6-A03A-E3EF65729F3D")
	   	Public Shared ReadOnly SampleMusic As New Guid("B250C668-F57D-4EE1-A63C-290EE7D1AA1F")
	   	Public Shared ReadOnly SamplePictures As New Guid("C4900540-2379-4C75-844B-64E6FAF8716B")
	   	Public Shared ReadOnly SamplePlaylists As New Guid("15CA69B3-30EE-49C1-ACE1-6B5EC372AFB5")
	   	Public Shared ReadOnly SampleVideos As New Guid("859EAD94-2E85-48AD-A71A-0969CB56A6CD")
	   	Public Shared ReadOnly SavedGames As New Guid("4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4")
	   	Public Shared ReadOnly SavedSearches As New Guid("7d1d3a04-debb-4115-95cf-2f29da2920da")
	   	Public Shared ReadOnly SEARCH_CSC As New Guid("ee32e446-31ca-4aba-814f-a5ebd2fd6d5e")
	   	Public Shared ReadOnly SEARCH_MAPI As New Guid("98ec0e18-2098-4d44-8644-66979315a281")
	   	Public Shared ReadOnly SearchHome As New Guid("190337d1-b8ca-4121-a639-6d472d16972a")
	   	Public Shared ReadOnly SendTo As New Guid("8983036C-27C0-404B-8F08-102D10DCFD74")
	   	Public Shared ReadOnly SidebarDefaultParts As New Guid("7B396E54-9EC5-4300-BE0A-2482EBAE1A26")
	   	Public Shared ReadOnly SidebarParts As New Guid("A75D362E-50FC-4fb7-AC2C-A8BEAA314493")
	   	Public Shared ReadOnly StartMenu As New Guid("625B53C3-AB48-4EC1-BA1F-A1EF4146FC19")
	   	Public Shared ReadOnly Startup As New Guid("B97D20BB-F46A-4C97-BA10-5E3608430854")
	   	Public Shared ReadOnly SyncManagerFolder As New Guid("43668BF8-C14E-49B2-97C9-747784D784B7")
	   	Public Shared ReadOnly SyncResultsFolder As New Guid("289a9a43-be44-4057-a41b-587a76d7e7f9")
	   	Public Shared ReadOnly SyncSetupFolder As New Guid("0F214138-B1D3-4a90-BBA9-27CBC0C5389A")
	   	Public Shared ReadOnly System As New Guid("1AC14E77-02E7-4E5D-B744-2EB1AE5198B7")
	   	Public Shared ReadOnly SystemX86 As New Guid("D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27")
	   	Public Shared ReadOnly Templates As New Guid("A63293E8-664E-48DB-A079-DF759E0509F7")
	   	Public Shared ReadOnly TreeProperties As New Guid("5b3749ad-b49f-49c1-83eb-15370fbd4882")
	   	Public Shared ReadOnly UserProfiles As New Guid("0762D272-C50A-4BB0-A382-697DCD729B80")
	   	Public Shared ReadOnly UsersFiles As New Guid("f3ce0f7c-4901-4acc-8648-d5d44b04ef8f")
	   	Public Shared ReadOnly Videos As New Guid("18989B1D-99B5-455B-841C-AB7C74E4DDFC")
	   	Public Shared ReadOnly Windows As New Guid("F38BF404-1D43-42F2-9305-67DE0B28FC23")
	End Class

	Public Declare Function SHGetKnownFolderPath Lib "shell32" _
	   	(ByRef knownFolder As Guid, _
 	   	ByVal flags As UInteger, _
 	   	ByVal htoken As IntPtr, _
 	   	ByRef path As IntPtr) As Integer

	Private Function GetFolder(ByVal pGuid As Guid) As String

	   	Dim txtOldTmp As String
	   	Dim ptPath As IntPtr

	   	If SHGetKnownFolderPath(pGuid, 0, IntPtr.Zero, ptPath) = 0 Then
   	       	txtOldTmp = System.Runtime.InteropServices.Marshal.PtrToStringUni(ptPath)
	   	End If

	   	GetFolder = txtOldTmp

	End Function

	Private Sub MainSub ()
	   	txtOldDocumentsPath.Text = GetFolder(KnownFolders.Documents)
	   	txtOldLinksPath.Text = GetFolder(KnownFolders.Links)
	   	txtOldDownloadsPath.Text = GetFolder(KnownFolders.Downloads)
	   	' and so on

	End Sub
Best M84Speed
Reply With Quote

excel, known folders, shgetknownfolderpath, special folders, vb 2010

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
Windows 7 Special Folders
Windows 7 Special Folders
Windows 7 Special Folders Windows 7 Special Folders
Windows 7 Special Folders
Windows 7 Special Folders
Windows 7 Special Folders Windows 7 Special Folders Windows 7 Special Folders Windows 7 Special Folders Windows 7 Special Folders Windows 7 Special Folders Windows 7 Special Folders
Windows 7 Special Folders
Windows 7 Special Folders
Windows 7 Special Folders
Windows 7 Special Folders