C# 建立捷徑 以下代碼在2.0,3.0,3.5 下都可以正常運行,在4.0在報錯。
不知道那為仁兄知道在4.0下建立捷徑。
選擇 COM 選項卡並選擇 Windows Script Host Object Model
using IWshRuntimeLibrary;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string DesktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);//得到案頭檔案夾
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(DesktopPath + "\\自動建立+.lnk");
shortcut.TargetPath = @"%HOMEDRIVE%/Program Files\Internet Explorer\IEXPLORE.EXE";
shortcut.Arguments = "http://www.baidu.com";// 參數
shortcut.Description = "快捷連結到網站";
shortcut.WorkingDirectory = "E:\\Publish Web Site\\clcs";//程式所在檔案夾,在捷徑表徵圖點擊右鍵可以看到此屬性
shortcut.IconLocation = @"%HOMEDRIVE%/Program Files\Internet Explorer\IEXPLORE.EXE, 0";//表徵圖
shortcut.Hotkey = "CTRL+SHIFT+Z";//熱鍵
shortcut.WindowStyle = 1;
shortcut.Save();
}
}
}
備用:Asp.NET產生各種網頁捷徑(案頭url捷徑,收藏夾/開始菜單捷徑)