如何在 .exe 所在的同一文件夹中创建我的项目 .exe 的快捷方式?
How to create shortcut of my project .exe in the same folder were .exe is located?
这是我的代码:
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 所在的同一文件夹中创建一个快捷方式。我无法为此指定文件夹路径,因为我不知道其他人会在哪里解压它 运行 :(
当然可以。这正是您在使用 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();
}
这是我的代码:
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 所在的同一文件夹中创建一个快捷方式。我无法为此指定文件夹路径,因为我不知道其他人会在哪里解压它 运行 :(
当然可以。这正是您在使用 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();
}