示例#1
0
        static void StartMonitoringTaskbarForUAC()
        {
            Win32.RECT?taskbarLastItemRectangle = null;
#pragma warning disable 8321
            bool ChechForUACTaskbarItem()
            {
                Bitmap image = Win32.GetWindowBitmap(Win32.GetTaskbarWindow());

                var rect = Win32.GetTaskbarRect();

                int item_size = image.Height; // it's roughly square

                int item_right        = image.ContentHEnd();
                int item_left_offset  = item_right - item_size;
                int item_right_offset = image.Width - item_right;

                image = image.HCrop(item_left_offset, item_right_offset);

                rect.Left  += item_left_offset;
                rect.Right -= item_right_offset;

                if (taskbarLastItemRectangle.HasValue)
                {
                    if (Math.Abs(rect.Left - taskbarLastItemRectangle.Value.Left) >= item_size)
                    {
                        // new item has appeared on the taskbar

                        var half_size = item_size / 2;

                        // MessageBox.Show("Please activate the UAC prompt on the taskbar.");
                        Win32.FireMouseClick(rect.Left + half_size, rect.Top + half_size);

                        return(true);
                    }
                }

                taskbarLastItemRectangle = rect;
                return(false);
            }

            ThreadPool.QueueUserWorkItem(x =>
            {
                bool done = false;
                while (!done)
                {
                    // if (ChechForUACTaskbarItem())
                    //     break;
                    Thread.Sleep(1000);
                    Win32.SetForegroundWindow(Win32.GetTaskbarWindow());
                }
            });
        }
示例#2
0
 static void KeepTaskbarFocused()
 {
     ThreadPool.QueueUserWorkItem(x =>
     {
         bool done = false;
         while (!done)
         {
             Thread.Sleep(1000);
             count++;
             if (count < 4)
             {
                 Win32.SetActiveWindow(Win32.GetTaskbarWindow());
                 // Win32.SetForegroundWindow(Win32.GetTaskbarWindow());
             }
         }
     });
 }