我正在使用以下代码在 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();