1

I need to remove Application launch and "Pin this application to taskbar" from the taskbar context menu for an application. Reason is that the application cannot start standalone, it must be fed with information from another application.

Does anyone know how?

g t
  • 6,576
  • 6
  • 44
  • 83

2 Answers2

0

According to this post, you can use the Windows API Code Pack but the required classes are internal. The OP said that they copied 50k lines of code to get it working. I'm not sure if it's improved since that post but here's a workaround I just thought of. Since you can only pin EXE files (and shortcuts as per comment) to the taskbar, you could rename your application to a non-exe extension (most non-exe extensions cannot be pinned).

When you want to call it from your other app, rename it to .exe, launch it, then rename it back again. For example:

Process p = new Process();
//fake extension so it can't be drag/dropped to taskbar
string fakeExtensionName = @"C:\MyFile\myProgram.test";
//what it's actually called
string exeExtensionName = @"C:\MyFile\myProgram.exe";
//rename the fake one to the real one
File.Move(fakeExtensionName, exeExtensionName);
p.StartInfo.FileName = exeExtensionName;
//launch the real one
p.Start();
//rename it back to the fake extension
File.Move(exeExtensionName, fakeExtensionName);

Anyone can rename it to an exe if they really wanted to, so your program should assume that a user can launch it directly and handle that scenario, but any file can be pinned to the taskbar by renaming it to an exe so there's no protection around that.

Community
  • 1
  • 1
keyboardP
  • 66,755
  • 13
  • 145
  • 199
  • Today I learned that the only thing that determines whether a file can be pinned onto the taskbar is if it has the `.exe` extension. – BoltClock Apr 22 '13 at 11:44
  • @BoltClock - I may be incorrect in saying it's the only extension but certainly one of the few. That's why a neat hack is to rename any file you want to pin as an exe, then right click on it, edit properties, and set the target path back to the original file format ;) – keyboardP Apr 22 '13 at 11:45
  • is it possible to rename the file when the application is running? – Andreas Johansson Apr 22 '13 at 11:48
  • you can pin everything to the taskbar, see `C:\Users\:Username\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar` – EaterOfCode Apr 22 '13 at 11:50
  • @AndreasJohansson - Yes, it should be, but if that could cause a problem with your application then you can rename it at a later time when you know your application is closed. I just renamed it back immediately as an example. – keyboardP Apr 22 '13 at 11:50
  • @EaterOfCorpses - Oh yes I should add shortcuts can be added as well but that's not preventable. A shortcut can be made to any file by the user so ultimately OP will have to handle the application being called directly. But this will prevent the user from drag/dropping the exe directly to the taskbar. – keyboardP Apr 22 '13 at 11:54
  • This is a wrong approach in my opinion. When you run the program, the renamed one, it will appear in Taskbar, so the user can select Pin to taskbar. I think he must update the architecture of the program. Use a dll file instead of an exe file. What do you want to achieve ? Do you have an exe file and you want to remove Pin to taskbar feature ? Why would you bother with that ? If the user will pin it by mistake, it will not work. This is not a problem. – Alexandru Dicu Apr 22 '13 at 11:55
  • @alexandrudicu - I'm taking this to be more of a UX aspect than a security aspect. A user might accidentally drag/drop the exe thinking it's possible to launch it directly. If they really want to call it directly there are plenty of ways of doing it. – keyboardP Apr 22 '13 at 11:57
  • Yes, this is a UX aspect! I will prevent incorrect usage in the application itself. But it would be nice to have functionality that is acually supported in the context menu. Otherwise it would be like having a "Save as..." Menu option that pops a MessageBox saying that it is not supported. Ugly if you ask me :) – Andreas Johansson Apr 22 '13 at 12:28
0

Ok, i found a ugly but easy solution here https://stackoverflow.com/a/3872503/1323570

apparantly the registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileAssociation\AddRemoveNames contains some words that may not exist in an executable if pinning should be possible.

you can also read more here: http://www.west-wind.com/weblog/posts/2009/Oct/08/Application-that-wont-Pin-to-Taskbar-in-Windows-7

Edit:

Found the way to do it properly:

Add the key:

HKEY_CLASSES_ROOT\Applications\Example.exe\NoStartPage

ref: http://msdn.microsoft.com/en-us/library/windows/desktop/hh127439(v=vs.85).aspx

Community
  • 1
  • 1