473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,396 developers and data experts.

Find users special folders (such as desktop/My documents)

TheSmileyCoder
2,322 Expert Mod 2GB
It can often be usefull to know what the path is to the users desktop, or his/her My Documents folder. The problem is that these folder paths can be changed by the user. However windows comes with built in support for accessing these values. The function here will let you get that information quite easy.

This will also work regardless of the language setup on the users computer (which is important since this affects the naming of some folders like My Documents.

Expand|Select|Wrap|Line Numbers
  1. Public Function SpecialFolderPath(strFolder As String) As String
  2.     ' Find out the path to the passed special folder. User on of the following arguments:
  3.     ' Options For specical folders
  4. '        AllUsersDesktop
  5. '        AllUsersStartMenu
  6. '        AllUsersPrograms
  7. '        AllUsersStartup
  8. '        Desktop
  9. '        Favorites
  10. '        Fonts
  11. '        MyDocuments
  12. '        NetHood
  13. '        PrintHood
  14. '        Programs
  15. '        Recent
  16. '        SendTo
  17. '        StartMenu
  18. '        Startup
  19. '        Templates
  20.  
  21.    On Error GoTo ErrorHandler
  22.  
  23.    'Create a Windows Script Host Object
  24.       Dim objWSHShell As Object
  25.       Set objWSHShell = CreateObject("WScript.Shell")
  26.  
  27.    'Retrieve path
  28.       SpecialFolderPath = objWSHShell.SpecialFolders(strFolder & "")
  29.  
  30.    ' Clean up
  31.       Set objWSHShell = Nothing
  32.       Exit Function
  33.  
  34. '**************************************
  35. '*      Error Handler
  36. '**************************************
  37. ErrorHandler:
  38.     MsgBox "Error finding " & strFolder, vbCritical + vbOKOnly, "Error"
  39. End Function
Mar 2 '12 #1
0 18722

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Colin Steadman | last post by:
I'm just starting out writing Python scripts (in PSP), and need to find the location of Windows special folders such as 'My Documents' and 'Desktop' so that I can save files in the right place. Is...
2
by: Bill English | last post by:
I want the initial directory of my save file dialog to be the My Documents folder. I know that that can vary, so is there a class that contains these special folder? What I would like is ...
1
by: news.microsoft.com | last post by:
I'm researching ways to locate so-called special folders such as "My Documents", "<username>\Application Data", etc. I've found references to Application.CommonAppDataPath(), etc, but those are...
2
by: Bob Hanson | last post by:
Hello All, I noticed in the ASP.NET beta 2 that we have more special folders. Can I get some clarification regarding these folders? I am just making sure of the intent. Thanks in advance, ...
12
by: Quemasda | last post by:
Hi, The application I'm working on should set the Special Folders (Favorites, My Documents, ...) but I can't find the way to do it. So far, I've been able to get the path of those Special...
3
by: DCC | last post by:
I need to resolve Windows special folders. From what I have read it would seem that using CSIDL's and SHGetSpecialFolderPath and SHGetFolderPath was the way to accomplish that in VB6 and VB.NET. ...
12
by: wheels619 | last post by:
How can I get access for another user's special folder locations? A configuration file is stored in the users' appData folder and the program altering it will be ran under the admin.
11
by: frogman7 | last post by:
what i am trying to do is something similar to the search that windows does to find files and folders. I am putting a start directory and want to find all the file (including the files in the sub...
2
by: Bruce Cleaver | last post by:
Hello, I've been trying to find a way to enumerate all drives- logical and virtual starting at the desktop for an explorer clone. I know how to get the logical drives and icons, but have not...
2
by: Ahsan123pk | last post by:
I have used StringTokenizer class to make tokens of a string but my program tokenizes a string only on the basis of spaces but it does not tokenizes on the basis of special characters such as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.