搜索并删除快捷方式
问题描述:
我正在从事的项目必须在Windows启动时运行,我找到了代码,但如果用户不想在启动时启动!我是否必须告诉用户搜索sortcut并删除它,或者干脆让该选项的按钮,我知道如何删除这样的文件:搜索并删除快捷方式
if(File.Exists(@"C:\Users\Maged\Desktop\remainder\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe"))
{
File.Delete(@"C:\Users\Maged\Desktop\remainder\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe");
}
我需要让程序searsh为MyStartupShortcut.lnk
如果将其删除存在。
这里是我创建的快捷代码:
void CreateStartupShortcut()
{
string startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
WshShell shell = new WshShell();
string shortcutAddress = startupFolder + @"\MyStartupShortcut.lnk";
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
shortcut.Description = "A startup shortcut. If you delete this shortcut from your computer, LaunchOnStartup.exe will not launch on Windows Startup";
shortcut.WorkingDirectory = Application.StartupPath;
shortcut.TargetPath = Application.ExecutablePath;
shortcut.Save();
}
我需要删除此文件,无论导演,任何帮助吗?
答
使用shortcutAddress
作为CreateStartupShortcut
法快捷方式的缺失应与代码实现创建:
if (File.Exists(shortcutAddress))
{
File.Delete(shortcutAddress);
}
正如你所知道的快捷方式的创建,并显示您所有的代码,你知道在哪里位于快捷方式 - 请参阅代码中的“shortcutAddress”。因此删除它应该很容易。问题顶部显示的代码会删除可执行文件,而不是快捷方式,因此似乎与删除快捷方式的问题无关。 – AdrianHHH
我知道快捷方式的位置,但是当用户运行它时,它会根据他的机器进行更改,所以我需要进行搜索并为他删除该快捷方式 –
我想我在'shortcutAddress'位置上获得您的意见,那么如何使用那个位置删除预制子 –