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:
- Start a new VB project.
- Open Notepad and copy the code below into Notepad. Save the file as SpecialGroups.frm.
- Add your just-saved SpecialGroups.frm file to your new project.
- Add a reference to the x:\Microsoft Visual Studio\VB98\VB\UNSUPPRT\SHELLLNK\ Shelllnk.vbp to your project group.
- 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.00
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
End
Begin VB.Label Label1
BorderStyle = 1 'Fixed Single
Height = 300
Left = 144
TabIndex = 0
Top = 612
Width = 4872
End
End
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
.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 With
End Sub