Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.DarkGray;
            Console.WriteLine("PinToTaskbarHelper");
            Console.WriteLine("Created by Nicolas Mehlei, 2018");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine();

            if (args.Length == 0)
            {
                Console.WriteLine("Usage: PinToTaskbarHelper.exe PATH");
            }
            else if (args.Length > 1)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Warning: Too many arguments");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Usage: PinToTaskbarHelper.exe PATH");
            }
            else
            {
                Console.Write("Creating application pin, please wait...");

                var path = args[0];
                try
                {
                    TaskbarPinHelper.PinApplication(path);
                    Console.WriteLine("done");
                }
                catch (Exception exc)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("ERROR");
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.Write("StackTrace: ");
                    Console.WriteLine(exc.ToString());
                }
            }
        }
        // Methods

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new OpenFileDialog
            {
                Filter = "Executables (*.exe)"
            };

            if (dlg.ShowDialog() == true)
            {
                _model.IsCreatingShortcut = true;

                try
                {
                    TaskbarPinHelper.PinApplication(dlg.FileName);
                }
                catch (Exception exc)
                {
                    MessageBox.Show("There was an error while creating the taskbar pin!" + Environment.NewLine + Environment.NewLine
                                    + exc, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                _model.IsCreatingShortcut = false;
            }
        }