C#处理快捷方式如下:
1、快捷方式包含如下数据:
·快捷方式的名字
·快捷方式所指向的目标所在的位置
·快捷方式所指向的目标的工作目录
·激活该快捷方式的热键
·快捷方式所指向的目标运行时的窗口风格(普通、最大化和最小化)
·该快捷方式的描述性文字
·快捷方式的图标所在的位置
2、在工程中选择 COM 选项卡并选择 Windows Script Host Object Model。
如图:
VS2005的实现方式:
我们用C#创建了指向"e://Serv-U.mdb"快捷方式及有关设置,现在反过来,已经知道一个快捷方式:my.lnk,怎样得到它包含的有关信息呢?代码如下:
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("c://" + "my.lnk");
//得到指定目标路径及文件名
MessageBox.Show(shortcut.TargetPath);
//得到描述
MessageBox.Show(shortcut.Description);
//得到图标类型
MessageBox.Show(shortcut.IconLocation);
vs2010的实现方式是:
IWshShortcut _shortcut=null;
IWshShell_Class shell = new IWshShell_Class();
if(System.IO.File.Exists(path)==true)
_shortcut = shell.CreateShortcut(path) as IWshShortcut;//在vs2010中CreateShortcut返回dynamic 类型
//所以要加as 进行对象类型转换
path1 = _shortcut.TargetPath;