2

I am aware of the solutions answered here. Basically the idea is to create a link to folder in the %USERPROFILE%\Favoriates folder.

However it doesn't work for me. I'm using Windows8 (don't know if that matters). In my %USERPROFILE%\Favoriates, it contains favoriate items for IE, not the file explorer.

I tried to locate this settings in registry and file system by creating a folder with very unique name and adding it to file explorer favoriates. Then search for the name in registry and file system. Didn't yield anything.

Community
  • 1
  • 1
KFL
  • 17,162
  • 17
  • 65
  • 89
  • The Favorites list is intended to be under user control. Applications should not be inserting them into the user's Favorites. This leads to unhappy users. – Raymond Chen May 20 '13 at 20:29

5 Answers5

4

It looks like you want %UserProfile%\Links.

Pinned favorites

Jimmy
  • 27,142
  • 5
  • 87
  • 100
4

Programmatically, you want to retrieve the location using SHGetKnownFolderPath with KNOWNFOLDERID_Links, instead of hard-coding any location, and then use IShellLink to create the shortcut file in that location.

Here is a C# example for the first part:

[DllImport("shell32.dll")]
static extern int SHGetKnownFolderPath(
                      [MarshalAs(UnmanagedType.LPStruct)] Guid knownFolderId, 
                      uint flags,
                      IntPtr userToken,
                      [MarshalAs(UnmanagedType.LPWStr)] out string knownFolderPath);

// this corresponds to the KNOWNFOLDERID_Links constant:
public static readonly Guid Links = new Guid("bfb9d5e0-c6a9-404c-b2b2-ae6db6af4968");

public static string GetKnownFolderPath(Guid knownFolderId)
{
    string path;
    int result = SHGetKnownFolderPath(knownFolderId, 0, IntPtr.Zero, out path);
    // … (error handling; check result for E_FAIL, E_INVALIDARG, or S_OK)
    return path;
}
stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
Ken White
  • 123,280
  • 14
  • 225
  • 444
0

Ah, looks like for Windows 8 this location has changed to %USERPROFILE%\Links, rather than %USERPROFILE%\Favoriates.

So to answer my question. To programmically add a folder to the Favoriates in Windows 8 file explorer, you need to make a link to that folder in the %USERPROFILE%\Links folder:

mklink /D %USERPROFILE%\Links\<Link_Name> <Tartget_Folder_Path>
KFL
  • 17,162
  • 17
  • 65
  • 89
0

The Explorer Favorites are stored here %USERPROFILE%\Links.

David Ruhmann
  • 11,064
  • 4
  • 37
  • 47
0
Function AddAFolderShortCut($fileName, $targetPath)
{
    Write-Host "Creating Shortcut $fileName points to $targetPath"
    $WshShell = New-Object -comObject WScript.Shell
    $Shortcut = $WshShell.CreateShortcut("$env:USERPROFILE\Links\$fileName.lnk")
    $Shortcut.TargetPath = $targetPath
    $Shortcut.Save()
}

AddAFolderShortCut "FolderName" "C:\folderpath"
Demodave
  • 6,242
  • 6
  • 43
  • 58