Я нашел некоторую информацию в Интернете. , но у меня возникли проблемы с его стабильной работой.
Я нашел API, который помогает закрепить текущее приложение на панели задач, но я хочу закрепить его ярлык\
Я также пробовал использовать powershell, но он не работает
Вот код, который я использовал:\
Код: Выделить всё
private static void PinShortcutToTaskbar(string shortcutPath)
{
// Path to the Taskbar's pinned items folder
string taskbarPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\Taskbar");
try
{
// Define the destination path
string destinationPath = Path.Combine(taskbarPath, Path.GetFileName(shortcutPath));
// Copy the shortcut to the taskbar pinned items folder
File.Copy(shortcutPath, destinationPath, true);
// Using Shell.Application to invoke the pin command
var shell = new Shell32.Shell();
var folder = shell.NameSpace(taskbarPath);
var folderItem = folder.ParseName(Path.GetFileName(shortcutPath));
// Invoke the pin command
folderItem.InvokeVerb("pintaskbar");
}
catch (Exception ex)
{
Console.WriteLine($"Failed to pin shortcut: {ex.Message}");
}
}
Я попробовал код по следующей ссылке:
https://learn.microsoft.com/en-us/answe ... to-taskbar\
https://stackoverflow.com/questions/317 ... windows-10\
https://stackoverflow.com/questions/74809556/ win-11-pin-unpin-a-shortcut-programmatically-using-c-sharp\
Я хочу добиться того же, что показано на снимке экрана
введите описание изображения здесь
п>
Подробнее здесь: https://stackoverflow.com/questions/790 ... ng-c-sharp