Search code examples
windows-10favorites

How to add shortcut link in "Quick Access" in Windows 10 through code?


I want to add shortcut link of one of the folder location to "Quick Access" in windows 10.

In the case of Windows 7 & Windows 8, I used to put my shortcut link in the folder "C:\Users\user_name\Links" & it showed me shortcut in favorites at left side. So I want to do same thing for Windows 10.

I directly copy shortcut & pasted into the location of Quick Access. But still it's not showing in left panel of Quick Access. As i know there are two option in Quick Access : 1. Frequent Folders & 2. Frequent Files.

So at what location do I need to put that shortcut link so it will appear in Quick Access section in left panel ?

And also I wanted to ask, how "OneDrive" link they have added in left panel in Windows 10 ? So is there any registry entry or any specific location ?


Solution

  • I am using following code to create folder shortcut at c:\users\user_name\links and it is working fine in windows 7 & 8 but can't see it under windows 10 quick access link in windows explorer.

    string sLinkFileName = "c:\users\user_name\links\\" + DefineString.AppName + ".lnk";
                FileInfo objfiLinkFile = new FileInfo(sLinkFileName);
                if (objfiLinkFile.Exists)
                {
                    try
                    {
                        objfiLinkFile.Delete();
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(LoggingLevel.Info, MethodBase.GetCurrentMethod().Name, string.Empty, ex);
                    }
                }
    
                //Place a shortcut to the file in the special folder 
                objfiLinkFile.Refresh();
                if (objfiLinkFile.Exists)
                {
                    Logger.Log(LoggingLevel.Info, MethodBase.GetCurrentMethod().Name, "Old link file still exists.");
                }
                // Create a shortcut in the special folder for the file
                // Making use of the Windows Scripting Host
                IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
                IWshRuntimeLibrary.IWshShortcut link = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(objfiLinkFile.FullName);
                link.TargetPath = Utils.msApplicationRootPath;
                link.WindowStyle = 1;
                link.Description = string.Format(DefineString.m00025, DefineString.AppName);
                link.IconLocation = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\RootFolder.ico";
                link.Save();
    

    I also tried to call mklink as you mentioned; but it didn't work. Unfortunately we don't have any direct control over user desktop. mklink command requires admin privileges? Which mklink command you used to fix the issue. Your help will be greatly appreciated.

    Process process = new Process();
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                startInfo.FileName = "cmd.exe";
                startInfo.Arguments = string.Format(@"/C mklink {0} {1}", sLinkFileName, Utils.msApplicationRootPath);
                process.StartInfo = startInfo;
                process.Start();