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