devxlogo

Special Folder Path

Special Folder Path

Question:
I want to find the path to the Startup special folder. How can this be done within a VB application?

Answer:
It takes a couple of steps, but is actually pretty easy:

  1. Start a new VB project.
  2. Open Notepad and copy the code below into Notepad. Save the file as SpecialGroups.frm.
  3. Add your just-saved SpecialGroups.frm file to your new project.
  4. Add a reference to the x:Microsoft Visual StudioVB98VBUNSUPPRTSHELLLNK Shelllnk.vbp to your project group.
  5. Run the program. By selecting the appropriate combo item, you can get the path of any of the special directories, including Startup.

Here’s the code to paste into your SpecialGroups.frm file in Notepad:

VERSION 5.00Begin VB.Form Form1    Caption         =   "Special Folders"   ClientHeight    =   1212   ClientLeft      =   876   ClientTop       =   1908   ClientWidth     =   5340   LinkTopic       =   "Form1"   ScaleHeight     =   1212   ScaleWidth      =   5340   Begin VB.ComboBox Combo1       Height          =   288      Left            =   144      Style           =   2  'Dropdown List      TabIndex        =   1      Top             =   216      Width           =   4872   End   Begin VB.Label Label1       BorderStyle     =   1  'Fixed Single      Height          =   300      Left            =   144      TabIndex        =   0      Top             =   612      Width           =   4872   EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption ExplicitPrivate Sub Combo1_Click()    Dim rc As Long    Dim sLnk As cShellLink    Dim sfPath As String    Dim Id As Long        ' Create instance of Explorer's IShellLink Interface Base Class    Set sLnk = New cShellLink        Id = Me.Combo1.ItemData(Me.Combo1.ListIndex)    Me.Label1.Caption = ""    If sLnk.GetSystemFolderPath(Me.hwnd, Id, sfPath) Then      Me.Label1.Caption = sfPath    End If        Set sLnk = NothingEnd SubPrivate Sub Form_Load()        With Me.Combo1        .AddItem "DESKTOP"        .ItemData(.NewIndex) = 0        .AddItem "PROGRAMS"        .ItemData(.NewIndex) = &H2        .AddItem "Controls"        .ItemData(.NewIndex) = &H3        .AddItem "Printers"        .ItemData(.NewIndex) = &H4        .AddItem "PERSONAL"        .ItemData(.NewIndex) = &H5        .AddItem "FAVORITES"        .ItemData(.NewIndex) = &H6        .AddItem "STARTUP"        .ItemData(.NewIndex) = &H7        .AddItem "RECENT"        .ItemData(.NewIndex) = &H8        .AddItem "SENDTO"        .ItemData(.NewIndex) = &H9        .AddItem "BITBUCKET: RECYCLE-BIN"        .ItemData(.NewIndex) = &HA        .AddItem "STARTMENU"        .ItemData(.NewIndex) = &HB        .AddItem "DESKTOPDIRECTORY"        .ItemData(.NewIndex) = &H10        .AddItem "DRIVES"        .ItemData(.NewIndex) = &H11        .AddItem "NETWORK"        .ItemData(.NewIndex) = &H12        .AddItem "NETHOOD"        .ItemData(.NewIndex) = &H13        .AddItem "Fonts"        .ItemData(.NewIndex) = &H14        .AddItem "TEMPLATES"        .ItemData(.NewIndex) = &H15        .AddItem "COMMON_STARTMENU"        .ItemData(.NewIndex) = &H16        .AddItem "COMMON_PROGRAMS"        .ItemData(.NewIndex) = &H17        .AddItem "COMMON_STARTUP"        .ItemData(.NewIndex) = &H18        .AddItem "COMMON_DESKTOPDIRECTORY"        .ItemData(.NewIndex) = &H19        .AddItem "APPDATA"        .ItemData(.NewIndex) = &H1A        .AddItem "PRINTHOOD"        .ItemData(.NewIndex) = &H1B                .ListIndex = 0    End WithEnd Sub

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist