سؤال

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?

هل كانت مفيدة؟

المحلول 2

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

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top