这是我的代码:
private void button_Click_1(object sender, RoutedEventArgs e)
{
string link = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
+ System.IO.Path.DirectorySeparatorChar + System.Windows.Forms.Application.ProductName + ".lnk";
var shell = new WshShell();
var shortcut = shell.CreateShortcut(link) as IWshShortcut;
shortcut.TargetPath = System.Windows.Forms.Application.ExecutablePath;
shortcut.WorkingDirectory = System.Windows.Forms.Application.StartupPath;
//shortcut...
shortcut.Save();
}
此代码在桌面上创建一个快捷方式...我想在我的exe所在的同一文件夹中创建一个快捷方式。我无法为此指向文件夹路径,因为我不知道其他人将解压缩它并运行它:(
答案 0 :(得分:0)
当然可以。当你使用Environment.SpecialFolder.Desktop
时,这正是你所说的创建它的地方。为什么你会期望它出现在其他地方?
您需要使用与shortcut.WorkingDirectory
分配的相同位置。
private void button_Click_1(object sender, RoutedEventArgs e)
{
string link = System.Windows.Forms.Application.StartupPath +
System.IO.Path.DirectorySeparatorChar +
System.Windows.Forms.Application.ProductName + ".lnk";
var shell = new WshShell();
var shortcut = shell.CreateShortcut(link) as IWshShortcut;
shortcut.TargetPath = System.Windows.Forms.Application.ExecutablePath;
shortcut.WorkingDirectory = System.Windows.Forms.Application.StartupPath;
//shortcut...
shortcut.Save();
}