本文实例讲述了C#实现将程序锁定到Win7任务栏的方法。分享给大家供大家参考。具体实现方法如下:
Win7Taskbar类:
using System;using System.Collections.Generic;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; } }}
调用方法:
string appPath = @"C:/Windows/notepad.exe";Console.WriteLine(Win7Taskbar.LockApp(true, appPath) ? "锁定程序成功" : "锁定程序失败");Console.ReadKey();Console.WriteLine(Win7Taskbar.LockApp(false, appPath) ? "解锁程序成功" : "解锁程序失败");
PS:
1.这个只适合中文系统,其他语言系统,请自己鼠标右键程序找Verb名换上即可
2.必须要引用 Interop.Shell32.dll
希望本文所述对大家的C#程序设计有所帮助。
新闻热点
疑难解答