安装 Mozilla Firefox 时,安装程序将 Mozilla 固定在任务栏中,我也想要它!!!
我正在使用 VS2010
安装 Mozilla Firefox 时,安装程序将 Mozilla 固定在任务栏中,我也想要它!!!
我正在使用 VS2010
从任务栏和开始菜单固定到/取消固定的 Vb.net 代码片段。(框架 3.5)
Dim shellApplication As Shell = New ShellClass()
Dim directoryName As String = Path.GetDirectoryName(filePath)
Dim fileName As String = Path.GetFileName(filePath)
Dim directory As Shell32.Folder = shellApplication.[NameSpace](directoryName)
Dim link As FolderItem = directory.ParseName(fileName)
Dim verbs As FolderItemVerbs = link.Verbs()
For i As Integer = 0 To verbs.Count - 1
Dim verb As FolderItemVerb = verbs.Item(i)
Dim verbName As String = verb.Name.Replace("&", String.Empty)
If (verbName.Equals("Pin to Start Menu")) Or (verbName.Equals("Unpin from Start Menu")) Then
verb.DoIt()
End If
Next
shellApplication = Nothing
'filePath 是要固定/取消固定任务栏的 .exe 文件的路径
在固定/取消固定任务栏的情况下,将“固定到开始菜单”替换为“固定到任务栏”,将“从开始菜单取消固定”替换为“从任务栏取消固定”
所有固定的文件都位于
C:\Users\%LoggedIn_User_Name%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned
此代码适用于 Windows7 美国英语。
干杯!
private static void PinUnpinTaskBar(string filePath, bool pin) {
if (!File.Exists(filePath)) throw new FileNotFoundException(filePath);
// create the shell application object
Shell shellApplication = new ShellClass();
string path = Path.GetDirectoryName(filePath);
string fileName = Path.GetFileName(filePath);
Folder directory = shellApplication.NameSpace(path);
FolderItem link = directory.ParseName(fileName);
FolderItemVerbs verbs = link.Verbs();
for (int i = 0; i < verbs.Count; i++) {
FolderItemVerb verb = verbs.Item(i);
string verbName = verb.Name.Replace(@"&", string.Empty).ToLower();
if ((pin && verbName.Equals("pin to taskbar")) || (!pin && verbName.Equals("unpin from taskbar"))) {
verb.DoIt();
}
}
shellApplication = null;
}
请务必包含“Microsoft Shell 控件和自动化”参考
并感谢@James Johnston - 他的原始帖子