本功借鉴妖哥的Blog
http://blog.csdn.net/ccrun/article/details/6906471DotNetFramework 3.5,如果是2.0的话需要把System.Linq去掉
C#版代码Win7Taskbar类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; }
}
}
调用方法string appPath = @"C:\Windows\notepad.exe";
Console.WriteLine(Win7Taskbar.LockApp(true, appPath) ? "锁定程序成功" : "锁定程序失败");Console.ReadKey();Console.WriteLine(Win7Taskbar.LockApp(false, appPath) ? "解锁程序成功" : "解锁程序失败");
http://blog.csdn.net/ccrun/article/details/6906471DotNetFramework 3.5,如果是2.0的话需要把System.Linq去掉
C#版代码Win7Taskbar类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; }
}
}
调用方法string appPath = @"C:\Windows\notepad.exe";
Console.WriteLine(Win7Taskbar.LockApp(true, appPath) ? "锁定程序成功" : "锁定程序失败");Console.ReadKey();Console.WriteLine(Win7Taskbar.LockApp(false, appPath) ? "解锁程序成功" : "解锁程序失败");
解决方案 »
- 如何获取DataGridView控件上修改后的值?
- 接口有什么好处?和超类有什么区别?接口如何使用?
- 在DataGridView的单元格中如何控制用户的输入法不是全角?
- 散分咯~~
- 新手用XmlReaderSettings 读XML文件。。。老是不行。请指教
- 高手请进(很急):如何把图片插入Excel的一个单元格中??
- excel的RANGE使用出错,三天没解决了,现在还在加班~~~有谁知道,分不够再加啊~~只要能解决问题
- 请问中文版和英文版.net 2003可以装在同一台机器上吗?
- 关于计费程序数据库操求个好方法
- 服务端与客户端消息传递
- 请教解密一字符串
- 无法加载 DLL“AspriseOCR.dll”: 找不到指定的模块
Win7有这个功能,这只是通过程序实现,说白了就是调用程序的右键菜单。
windows7下面Interop.Shell32.dll此插件位置:
C:\Windows\winsxs\x86_microsoft-windows-shell32_31bf3856ad364e35_6.1.7600.16385_none_6bff8101734f8330
像这种方法如果用在webFroms里面,是不是只能用在服务器端呀;
这个肯定是要用在服务器端了。不过服务器一般不会调Shell吧。那得需要什么功能。
论坛签名======================================================================dodducs:你好!
截至 2011-10-26 16:26:48 前:
你已发帖 22 个, 未结贴 0 个;
结贴率为: 100.00%
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html如何给分和结贴?
http://community.csdn.net/Help/HelpCenter.htm#结帖如何给自己的回帖中也加上签名?
http://blog.csdn.net/q107770540/archive/2011/03/15/6250007.aspx
那样也可以,这个是程序实现,比如你要做一个安装包工具,现在大多数选上添加到快速启动只能在XP下添加成功,在WIN7下是不好用的。通过这个方法,只要判断当前系统版本调用不同的方法即可实现添加自己的程序到快速启动栏。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shell32;
using System.IO;
using System.Runtime.InteropServices;namespace TestWin7Taskbar
{
class Win7Taskbar
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private extern static int LoadString(IntPtr hInstance,//应用程序实例句柄
UInt32 uID,//资源ID
StringBuilder lpBuffer,//存放字符串的缓冲区
int nBufferMax//缓冲区大小
); [DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
private extern static IntPtr LoadLibrary(string lpFileName);
[DllImport("kernel32.dll")]
private extern static bool FreeLibrary(IntPtr lib);
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)); StringBuilder sVerb = new StringBuilder(255);
IntPtr handler = LoadLibrary("Shell32.dll"); LoadString(handler, isLock ? 5386u : 5387u, sVerb, sVerb.Capacity + 1);
FreeLibrary(handler); foreach (FolderItemVerb Fib in app.Verbs())
{
if (Fib.Name == sVerb.ToString())
{
Fib.DoIt();
return true;
}
} return false; }
}
}
您好,想请教您一个问题。
如果我不想不想在项目里面添加Shell32.dll文件,因为这样的话发布exe文件时必须把Shell32文件也加上,不然运行不了,而是直接加载dll文件该如何写呢?