Add a link to Favorites side bar (Windows 7/2008)

The Favorites side bar in Explorer is found (in Windows 7/2008) under C:\Users\%username%\Links folder. By default, this folder contains three link (.lnk) files: Desktop.lnk, Downloads.lnk and RecentPlaces.lnk.

I wrote a VB script that you can append to your network login script to create new entries in this section.

Option Explicit

‘ Create link for J drive
‘ Passing the following information to CreateLinkFile Subroutine:
‘ First: Dfs link or URL destination path
‘ Second: Link description
‘ Third: Name of link (.lnk) file
CreateLinkFile “\\Dfs\link\OrSharePath\”, “A Description”, “NameOfLnkFile.lnk”

‘ =============================
‘ Create link files for J drive
‘ =============================
Sub CreateLinkFile ( LinkTargetPath, LinkDescription, LinkFileName )

‘ Variable declarations
Dim wshShell, oShellLink, fso, strLinkFilenameAndPath

‘ Set workspace environments
Set fso = CreateObject( “Scripting.FileSystemObject” )
Set wshShell = CreateObject( “WScript.Shell” )

‘ strLinkFilenameAndPath variable holds full path where .lnk file will be saved
‘ Path is based on environment variable %USERNAME%
strLinkFilenameAndPath = “C:\Users\” & wshShell.ExpandEnvironmentStrings ( “%USERNAME%” ) & “\Links\” & LinkFileName

‘ Llink will be created only if it doesn’t already exist
If Not fso.FileExists ( strLinkFilenameAndPath ) Then

‘ .LNK file to be created in C:\Users\%USERNAME%\Links folder
Set oShellLink = wshShell.CreateShortcut( strLinkFilenameAndPath )
oShellLink.TargetPath = LinkTargetPath ‘ Absolute path to the executable, file, folder, or URL
oShellLink.Description = LinkDescription ‘ Short description, optional
oShellLink.WindowStyle = “1”             ‘ 1 = Default, 3 = Maximized, 7 = Minimized
End If

End Sub

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: