473,902 Members | 4,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
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 19586

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

Similar topics

1
5278
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 there any method I can use in Python to get these? If I were doing this in VBScript it'd be: Dim WSHShell Set WSHShell = WScript.CreateObject("WScript.Shell") msgbox WSHShell.SpecialFolders("Desktop")
2
10004
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 OpenFileDialog.InitialDirectory = Class.MyDocuments
1
1802
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 too limiting. I'm really looking for managed-code equivalents of SHGetFolderPath(). Is there such a beast? Or will I need to do a DLLImport to get the flexibility I need? Cheers, Jon
2
1660
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, Bob Hanson
12
1830
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 Folders but not set them. Does anybody know how? Thanks in advance, Que_Mas_Da.
3
4310
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. Is this still the best method in VB 2005? If so does anyone have a working example of how to declare and call the functions? I have tried declaring the functions as follows: Private Declare Function SHGetFolderPath Lib "shell32.dll" _ Alias...
12
8036
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
2516
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 folders) so i can write each line to a master file. i have it working but it uses loops and it extremely slow. Is there a function that grabs all the files from a folder and subdirectories?
2
4021
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 found a way to get all the drives and folders. I think IShellFolder with enumobjects is used but I can't find an example. Thank you for your help.
2
3609
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 comma(,),full stop(.),single quotes etc. Consider a sentence or string: "I don't know who is he." After compiling it the output of my program is: I: valid token don't: valid token know: valid token who: valid token
0
9845
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11279
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10870
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7205
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4725
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4306
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3323
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.