Created
November 7, 2020 11:06
-
-
Save arcadepro/8acea45263c5e924142a87c583b28013 to your computer and use it in GitHub Desktop.
Powershell script to restart Logitech G software.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# reset-LCore.ps1 | |
# Set LCore to start when Windows starts. | |
# (If you need to start it manually, include the /minimized argument: LCore.exe /minimized ) | |
# Save this file to %USERPROFILE%\pshell\reset-LCore.ps1 | |
Add-Type -AssemblyName System.Windows.Forms | |
Add-Type @" | |
using System; | |
using System.Runtime.InteropServices; | |
public struct RECT { | |
public int left; | |
public int top; | |
public int right; | |
public int bottom; | |
} | |
public class pInvoke { | |
[DllImport("user32.dll")] | |
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); | |
[DllImport("user32.dll")] | |
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); | |
[DllImport("user32.dll")] | |
public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect); | |
[DllImport("user32.dll")] | |
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam); | |
public static void RefreshTrayArea() { | |
IntPtr systemTrayContainerHandle = FindWindow("Shell_TrayWnd", null); | |
IntPtr systemTrayHandle = FindWindowEx(systemTrayContainerHandle, IntPtr.Zero, "TrayNotifyWnd", null); | |
IntPtr sysPagerHandle = FindWindowEx(systemTrayHandle, IntPtr.Zero, "SysPager", null); | |
IntPtr notificationAreaHandle = FindWindowEx(sysPagerHandle, IntPtr.Zero, "ToolbarWindow32", "Notification Area"); | |
if (notificationAreaHandle == IntPtr.Zero) { | |
notificationAreaHandle = FindWindowEx(sysPagerHandle, IntPtr.Zero, "ToolbarWindow32", "User Promoted Notification Area"); | |
IntPtr notifyIconOverflowWindowHandle = FindWindow("NotifyIconOverflowWindow", null); | |
IntPtr overflowNotificationAreaHandle = FindWindowEx(notifyIconOverflowWindowHandle, IntPtr.Zero, "ToolbarWindow32", "Overflow Notification Area"); | |
RefreshTrayArea(overflowNotificationAreaHandle); | |
} | |
RefreshTrayArea(notificationAreaHandle); | |
} | |
private static void RefreshTrayArea(IntPtr windowHandle) { | |
const uint wmMousemove = 0x0200; | |
RECT rect; | |
GetClientRect(windowHandle, out rect); | |
for (var x = 0; x < rect.right; x += 5) | |
for (var y = 0; y < rect.bottom; y += 5) | |
SendMessage(windowHandle, wmMousemove, 0, (y << 16) + x); | |
} | |
} | |
"@ | |
$processName = "LCore" | |
$process = $(Get-Process $processName -ErrorAction SilentlyContinue)[0] | |
If ($process) { | |
$processId = $process.Id | |
$cmd = (Get-WmiObject Win32_Process -Filter "ProcessId = '$processId'").CommandLine | |
Stop-Process -Id $processId | |
Wait-Process -Id $processId | |
[pInvoke]::RefreshTrayArea() | |
Invoke-Expression "& $cmd" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment