svchost.exe -k UnistackSvcGroup CPU Usage in High On Windows 11

Disable Automatic Updates for Apps

Go to Microsoft Store and disable automatic update

Stop Service using Registry Editor

navigate to this location

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UnistoreSvc

Find and double click Start entry from the right pane

You will see a new Windows and it must have 3 in its value data section. The 3 here means that the service is manual.

Then, you have to change this value to 4 to solve the issue as “4: means this service is turned off.

Remove Contents of UnistoreDB Folder

navigate here

C:\Users\profile_name\AppData\Local\Comms\UnistoreDB

and delete all files there.

References
https://www.alfintechcomputer.com/how-to-remove-svchost-exe-unistacksvcgroup-from-task-manager-of-your-computer/

Move an Application Window From Off-screen Back to Your Main Desktop

  1. Right-click on the Windows taskbar and select Cascade windows from the pop-up menu.
  2. Hold down the Shift key, then right-click on the appropriate application icon in the Windows taskbar.
  3. On the resulting pop-up, select the Move option.
  4. Begin pressing the arrow keys on your keyboard to move the invisible window from off-screen to on-screen. Typically, you will use the left arrow to move the window from right to left.

References
https://support.ti.davidson.edu/hc/en-us/articles/115016089728-Move-an-Application-Window-From-Off-screen-Back-to-Your-Main-Desktop-Windows

Make a PyQT window bring to the front

from win32gui import SetWindowPos
import win32con

SetWindowPos(window.winId(),
             win32con.HWND_TOPMOST, # = always on top. only reliable way to bring it to the front on windows
             0, 0, 0, 0,
             win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_SHOWWINDOW)
SetWindowPos(window.winId(),
             win32con.HWND_NOTOPMOST, # disable the always on top, but leave window at its top position
             0, 0, 0, 0,
             win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_SHOWWINDOW)
window.raise_()
window.show()
window.activateWindow()

References
https://stackoverflow.com/questions/12118939/how-to-make-a-pyqt4-window-jump-to-the-front

Move and Click Mouse in C#

[DllImport("user32.dll")]
public static extern void mouse_event(MouseEventFlags dwFlags, uint dx, uint dy, uint dwData, MouseEventDataXButtons dwExtraInfo);

[DllImport("User32.Dll")]
public static extern long SetCursorPos(int x, int y);
[Flags]
public enum MouseEventFlags : uint
{
    LEFTDOWN = 0x00000002,
    LEFTUP = 0x00000004,
    MIDDLEDOWN = 0x00000020,
    MIDDLEUP = 0x00000040,
    MOVE = 0x00000001,
    ABSOLUTE = 0x00008000,
    RIGHTDOWN = 0x00000008,
    RIGHTUP = 0x00000010,
    WHEEL = 0x00000800,
    XDOWN = 0x00000080,
    XUP = 0x00000100
}

//Use the values of this enum for the 'dwData' parameter
//to specify an X button when using MouseEventFlags.XDOWN or
//MouseEventFlags.XUP for the dwFlags parameter.
public enum MouseEventDataXButtons : uint
{
    XBUTTON1 = 0x00000001,
    XBUTTON2 = 0x00000002
}
public static void MoveMouse(int x, int y)
{
    PInvoke.SetCursorPos(x, y);
}

public static void ClickMouse(int x, int y)
{
    PInvoke.mouse_event(MouseEventFlags.LEFTDOWN | MouseEventFlags.ABSOLUTE, (uint)x, (uint)y, 0, 0);
    Thread.Sleep(10);
    PInvoke.mouse_event(MouseEventFlags.LEFTUP | MouseEventFlags.ABSOLUTE, (uint)x, (uint)y, 0, 0);
}

References
https://stackoverflow.com/questions/13520705/move-mouse-to-position-and-left-click
http://www.pinvoke.net/default.aspx/user32.mouse_event
https://stackoverflow.com/questions/8050825/how-to-move-mouse-cursor-using-c
https://www.pinvoke.net/default.aspx/user32.setcursorpos

Take Screenshot in C#

First Set Process DPI Aware:

Get Screen Size on C#
https://pupli.net/2020/03/get-screen-size-on-c/

Install-Package System.Drawing.Common -Version 7.0.0

Take screenshot and save to file

using System;
using System.Drawing;
using System.Windows.Forms;

namespace ScreenshotExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get the bounds of the screen
            Rectangle bounds = Screen.PrimaryScreen.Bounds;

            // Create a bitmap object to store the screenshot
            using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
            {
                // Create a graphics object from the bitmap
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    // Capture the screen
                    g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
                }

                // Save the screenshot as a PNG file
                bitmap.Save("screenshot.png");
            }

            Console.WriteLine("Screenshot saved as screenshot.png");
        }
    }
}

Take screenshot and save to memory

using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace ScreenshotToMemory
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get the bounds of the screen
            Rectangle bounds = Screen.PrimaryScreen.Bounds;

            // Create a bitmap object to store the screenshot
            using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
            {
                // Create a graphics object from the bitmap
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    // Capture the screen
                    g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
                }

                // Store the screenshot in memory using MemoryStream
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);

                    // Convert the MemoryStream to byte array
                    byte[] screenshotBytes = memoryStream.ToArray();

                    // Now the screenshot is stored in screenshotBytes, you can use it as needed
                    // For demonstration, let's output the length of the byte array
                    Console.WriteLine($"Screenshot captured. Byte array length: {screenshotBytes.Length}");
                }
            }
        }
    }
}

 

Get Screen Size on C#

The process is running under DPI virtualization. So we should apply the DPI aware manifest option to stop DPI virtualization

[DllImport("user32.dll", SetLastError=true)]
static extern bool SetProcessDPIAware();

Then

public enum SystemMetric
{
    VirtualScreenWidth = 78, // CXVIRTUALSCREEN 0x0000004E 
    VirtualScreenHeight = 79, // CYVIRTUALSCREEN 0x0000004F 
}

[DllImport("user32.dll")]
public static extern int GetSystemMetrics(SystemMetric metric);

public static Size GetVirtualDisplaySize()
{
    var width = GetSystemMetrics(SystemMetric.VirtualScreenWidth);
    var height = GetSystemMetrics(SystemMetric.VirtualScreenHeight);

    return new Size(width, height);
}

References
https://stackoverflow.com/questions/28339257/getsystemmetrics-and-tscreen-returns-wrong-value
https://www.pinvoke.net/default.aspx/user32/SetProcessDPIAware.html
https://stackoverflow.com/questions/1317235/c-get-complete-desktop-size
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setprocessdpiaware