Ich habe nach demselben Thema gesucht und die Lösung gefunden. Das Problem ist jedoch, dass die Namespace -Eigenschaft eine Ausnahme bietet. Ich habe es mit diesem Code ausprobiert: < /p>
public bool PinUnpinTaskbar(string filePath, bool pin)
{
if (!File.Exists(filePath)) throw new FileNotFoundException(filePath);
int MAX_PATH = 255;
var actionIndex = pin ? 5386 : 5387; // 5386 is the DLL index for"Pin to Tas&kbar", ref. http://www.win7dll.info/shell32_dll.html
//uncomment the following line to pin to start instead
//actionIndex = pin ? 51201 : 51394;
StringBuilder szPinToStartLocalized = new StringBuilder(MAX_PATH);
IntPtr hShell32 = LoadLibrary("Shell32.dll");
LoadString(hShell32, (uint)actionIndex, szPinToStartLocalized, MAX_PATH);
string localizedVerb = szPinToStartLocalized.ToString();
string path = Path.GetDirectoryName(filePath);
string fileName = Path.GetFileName(filePath);
// create the shell application object
//var shell = new Shell32.Shell();
dynamic shellApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));
dynamic directory = shellApplication.NameSpace(path);
dynamic link = directory.ParseName(fileName);
dynamic verbs = link.Verbs();
for (int i = 0; i < verbs.Count(); i++)
{
dynamic verb = verbs.Item(i);
if (verb.Name.Equals(localizedVerb))
{
verb.DoIt();
return true;
}
}
return false;
}
< /code>
Aber das Problem ist hier mit ShellApplication.namePace (Pfad). Es kann keine solche Eigenschaft/Methode finden. Ich habe nicht zu viel Idee dazu. Also wird jede Art von Hilfe geschätzt.
PIN -Anwendung in der Taskleiste mit C# ⇐ C#
-
- Similar Topics
- Replies
- Views
- Last post