/// <summary>
/// 获取整个文件夹中快捷方式
/// </summary>
/// <param name="path">文件夹路径</param>
private void GetShortcut(string path)
{
string driver = path.Substring(0, 2);
path = path.Substring(2) + "\\"; //WQL中的文件夹前后都有"\"
path = path.Replace("\\", "\\\\"); //WQL中的文件夹分隔符应是"\\"
string wsql = "Select * From Win32_ShortcutFile Where Drive='" + driver + "' and Path='" + path + "'";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(wsql);
if (searcher == null) return;
foreach (ManagementObject o in searcher.Get())
{
listBox1.Items.Add(o.GetPropertyValue("Name").ToString() + " => " + o.GetPropertyValue("Target").ToString());
}
}
/// <summary>
/// 根据单一快捷方式获取
/// </summary>
/// <param name="path"></param>
/// <param name="filename"></param>
private void GetShortCutByLnk(string path,string filename)
{
string driver = path.Substring(0, 2);
path = path.Substring(2) + "\\"; //WQL中的文件夹前后都有"\"
path = path.Replace("\\", "\\\\"); //WQL中的文件夹分隔符应是"\\"
string wsql = "Select * From Win32_ShortcutFile Where Drive='" + driver + "' and Path='" + path + "' and FileName ='" + filename + "'";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(wsql);
if (searcher == null) return;
foreach (ManagementObject o in searcher.Get())
{
listBox1.Items.Add(o.GetPropertyValue("Name").ToString() + " => " + o.GetPropertyValue("Target").ToString());
}
}
参考:
http://www.microsoft.com/china/technet/community/scriptcenter/resources/hey1208.mspx