Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: NT
Expertise: Beginner
Sep 8, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Special Folder Path

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

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 Studio\VB98\VB\UNSUPPRT\SHELLLNK\ 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:

Begin 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
   Begin VB.Label Label1 
      BorderStyle     =   1  'Fixed Single
      Height          =   300
      Left            =   144
      TabIndex        =   0
      Top             =   612
      Width           =   4872
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Option Explicit

Private 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 = Nothing
End Sub

Private 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
        .ItemData(.NewIndex) = &HA
        .AddItem "STARTMENU"
        .ItemData(.NewIndex) = &HB
        .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
        .ItemData(.NewIndex) = &H19
        .AddItem "APPDATA"
        .ItemData(.NewIndex) = &H1A
        .AddItem "PRINTHOOD"
        .ItemData(.NewIndex) = &H1B
        .ListIndex = 0
    End With
End Sub
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date