0
我正在從事的項目必須在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」。因此刪除它應該很容易。問題頂部顯示的代碼會刪除可執行文件,而不是快捷方式,因此似乎與刪除快捷方式的問題無關。 – AdrianHHH
我知道快捷方式的位置,但是當用戶運行它時,它會根據他的機器進行更改,所以我需要進行搜索併爲他刪除該快捷方式 –
我想我在'shortcutAddress'位置上獲得您的意見,那麼如何使用那個位置刪除預製子 –