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();
}
}
}
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();
}
}
}