Lonely_Child

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
/// <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

http://www.yiminbaike.com

美国酝酿计分制移民政策

posted on 2011-02-15 16:05  Lonely_Child  阅读(1067)  评论(2编辑  收藏  举报