When Mozilla Firefox installs, the installer pins Mozilla in taskbar, and I want it too!!!
I'm using VS2010
When Mozilla Firefox installs, the installer pins Mozilla in taskbar, and I want it too!!!
I'm using VS2010
Vb.net Code snippet for Pin to/Unpin from Task Bar and Start Menu. (framework 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 is the path of .exe file that you want to pin/Unpin taskbar
In Case of Pinning/Unpinning Taskbar replace "Pin to Start Menu" with "pin to taskbar" and "Unpin from Start Menu" to "unpin from taskbar"
All the pinned files resides in the
C:\Users\%LoggedIn_User_Name%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned
This Code is working on Windows7 US English.
Cheers!
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;
}
be sure to include the "Microsoft Shell Controls And Automation" reference
and say thanks to @James Johnston - his original post