把程序锁定到Win7任务栏

 把程序锁定到Win7任务栏 [问题点数:20]
  • dodducs
  • (苦工)
  • 等 级:
  • 结帖率:100.00%
楼主发表于:2011-10-26 16:26:48
本功借鉴妖哥的Blog
http://blog.csdn.net/ccrun/article/details/6906471

DotNetFramework 3.5,如果是2.0的话需要把System.Linq去掉
C#版代码

Win7Taskbar类
C# code
 
             
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Shell32; using System.IO; namespace TestWin7Taskbar { class Win7Taskbar { public static bool LockApp( bool isLock, string appPath) { Shell shell = new Shell(); Folder folder = shell.NameSpace(Path.GetDirectoryName(appPath)); FolderItem app = folder.ParseName(Path.GetFileName(appPath)); string sVerb = isLock ? " 锁定到任务栏(&K) " : " 从任务栏脱离(&K) " ; foreach (FolderItemVerb Fib in app.Verbs()) { if (Fib.Name == sVerb) { Fib.DoIt(); return true ; } } return false ; } } }


调用方法
C# code
 
             
string appPath = @" C:\Windows\notepad.exe " ; Console.WriteLine(Win7Taskbar.LockApp( true , appPath) ? " 锁定程序成功 " : " 锁定程序失败 " ); Console.ReadKey(); Console.WriteLine(Win7Taskbar.LockApp( false , appPath) ? " 解锁程序成功 " : " 解锁程序失败 " );

你可能感兴趣的:(把程序锁定到Win7任务栏)