【问题标题】:How to add shortcut link in "Quick Access" in Windows 10 through code?如何通过代码在 Windows 10 的“快速访问”中添加快捷方式链接?
【发布时间】:2023-03-07 00:57:01
【问题描述】:

我想将文件夹位置之一的快捷方式链接添加到 Windows 10 中的“快速访问”。

在 Windows 7 和 Windows 8 的情况下,我曾经将快捷方式链接放在文件夹“C:\Users\user_name\Links”中,它会在左侧的收藏夹中显示快捷方式。所以我想为 Windows 10 做同样的事情。

我直接复制快捷方式并粘贴到快速访问的位置。但它仍然没有显示在快速访问的左侧面板中。 据我所知,快速访问中有两个选项:1. 常用文件夹和 2. 常用文件。

那么我需要将该快捷链接放在什么位置,以便它出现在左侧面板的快速访问部分中?

我还想问,他们如何在 Windows 10 的左侧面板中添加“OneDrive”链接?那么是否有任何注册表项或任何特定位置?

【问题讨论】:

标签: windows-10 favorites


【解决方案1】:

我没有找到合适的解决方案。 但是我为我的问题应用了解决方法。 我在快速访问位置 (\Links) 创建了文件夹。并使用 mkilink cmd 我将它的符号链接更改为目标文件夹。我在使用 Process 的 C# 代码中使用 cmd 提示符使用 mklink。

【讨论】:

    【解决方案2】:

    我正在使用以下代码在 c:\users\user_name\links 创建文件夹快捷方式,它在 Windows 7 和 8 中运行良好,但在 Windows 资源管理器中的 Windows 10 快速访问链接下看不到它。

    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();
    

    我也尝试过调用 mklink,就像你提到的那样;但它没有用。不幸的是,我们无法直接控制用户桌面。 mklink 命令需要管理员权限?您用于解决问题的 mklink 命令。非常感谢您的帮助。

    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();
    

    【讨论】:

      【解决方案3】:

      你可以通过这个 powershell 脚本来做到这一点:

      $o = new-object -com shell.application
      $o.Namespace('c:\Folder').Self.InvokeVerb("pintohome")
      

      【讨论】:

        猜你喜欢
        • 2012-05-28
        • 2018-07-17
        • 2017-08-01
        • 2015-12-24
        • 2023-01-04
        • 2011-10-09
        • 2023-01-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多