BartoszCichecki / LenovoLegionToolkit

Lightweight Lenovo Vantage and Hotkeys replacement for Lenovo Legion laptops.
GNU General Public License v3.0
5.54k stars 249 forks source link

[FEAT]: Fallback to use process ID only for protected processes #338

Closed DavisR-GitHub closed 2 years ago

DavisR-GitHub commented 2 years ago

Version

2.6.4

OS

Windows 10 21H2 19044.2130

Device

Legion 5 17ACH6H

BIOS version

GKCN57WW

What's wrong?

I've added two actions:

  1. On app start (D:\Games\OriginGames\Apex\r5apex.exe - Apex Legends) - switch power plan to Balance
  2. On app stop (same r5apex.exe) - switch power plan to Quiet These actions do not work. Then I run with logging enabled and saw this:
    Log
[01.11.2022 09:52:49] [39] [GPUController.cs#203:RefreshLoopAsync] Will refresh...
[01.11.2022 09:52:49] [39] [GPUController.cs#242:RefreshStateAsync] Refresh in progress...
[01.11.2022 09:52:49] [39] [GPUController.cs#298:RefreshStateAsync] Monitor connected [status=MonitorsConnected, processes.Count=15, gpuInstanceId=]
[01.11.2022 09:52:49] [39] [GPUController.cs#209:RefreshLoopAsync] Refreshed
[01/11/2022 09:52:50] [14] [AbstractWMIListener.cs#84:Handler] Event received. [value=(Started, 11640, dllhost.exe), listener=InstanceEventListener]
[01/11/2022 09:52:50] [14] [AbstractWMIListener.cs#84:Handler] Event received. [value=(Started, 4924, r5apex.exe), listener=InstanceEventListener]
[01/11/2022 09:52:51] [14] [ProcessAutomationListener.cs#85:InstanceCreationListener_Changed] Can't get process r5apex.exe details.
=== Exception ===
System.ComponentModel.Win32Exception (5): Отказано в доступе.
   at System.Diagnostics.NtProcessManager.EnumProcessModulesUntilSuccess(SafeProcessHandle processHandle, IntPtr[] modules, Int32 size, Int32& needed)
   at System.Diagnostics.NtProcessManager.GetModules(Int32 processId, Boolean firstModuleOnly)
   at System.Diagnostics.NtProcessManager.GetFirstModule(Int32 processId)
   at System.Diagnostics.Process.get_MainModule()
   at LenovoLegionToolkit.Lib.Automation.Listeners.ProcessAutomationListener.InstanceCreationListener_Changed(Object sender, ValueTuple`3 e)

=== Exception demystified ===
System.ComponentModel.Win32Exception: Отказано в доступе.
   at void System.Diagnostics.NtProcessManager.EnumProcessModulesUntilSuccess(SafeProcessHandle processHandle, IntPtr[] modules, int size, out int needed)
   at ProcessModuleCollection System.Diagnostics.NtProcessManager.GetModules(int processId, bool firstModuleOnly)
   at ProcessModule System.Diagnostics.NtProcessManager.GetFirstModule(int processId)
   at ProcessModule System.Diagnostics.Process.get_MainModule()
   at void LenovoLegionToolkit.Lib.Automation.Listeners.ProcessAutomationListener.InstanceCreationListener_Changed(object sender, (ProcessEventInfoType type, int processID, string processName) e)

[01.11.2022 09:52:54] [39] [GPUController.cs#203:RefreshLoopAsync] Will refresh...
[01.11.2022 09:52:54] [39] [GPUController.cs#242:RefreshStateAsync] Refresh in progress...
[01.11.2022 09:52:54] [39] [GPUController.cs#298:RefreshStateAsync] Monitor connected [status=MonitorsConnected, processes.Count=15, gpuInstanceId=]
[01.11.2022 09:52:54] [39] [GPUController.cs#209:RefreshLoopAsync] Refreshed

I tested with another apps, strange things also:

How to reproduce the bug?

  1. Go to Actions
  2. add Action - On App start.
  3. Add r5apex.exe
  4. Add Step switch power plan
  5. Run Apex Legends
  6. Power plan does not switched

What is the behavior that you expected?

Power plan should switch to Balanced on Apex start and back to Quiet on Apex close

Logs

above

Do you have Lenovo software installed?

Did you disable any Lenovo software using Lenovo Legion Toolkit?

Additional information

No response

BartoszCichecki commented 2 years ago

That usually happens when a process is protected. For games, that usually means that an anticheat system is protecting the process and LLT can't get process' details.

But this issue just gave me an idea so I will change it into a feature request.

BartoszCichecki commented 2 years ago

Loosely related: #323

BartoszCichecki commented 2 years ago

Try this build. LenovoLegionToolkitSetup.zip

It may or may not help, but maybe it's worth trying.

BartoszCichecki commented 2 years ago

And regarding notepad.exe: exe files from Windows dir are ignored (performance optimization) because Windows is starting a lot of processes.

DavisR-GitHub commented 2 years ago

notepad.exe: exe files from Windows dir are ignored

I assumed that this is ignored for some reason. It is just my usual test application for such cases ;)

DavisR-GitHub commented 2 years ago

Does not work

build=20221101111224 ``` [01/11/2022 11:21:34.537] [17] [AbstractWMIListener.cs#84:Handler] Event received. [value=(Started, 5740, r5apex.exe), listener=InstanceEventListener] [01/11/2022 11:21:34.640] [17] [ProcessAutomationListener.cs#85:InstanceCreationListener_Changed] Can't get process r5apex.exe details, fallback to ID only. [01/11/2022 11:21:34.641] [17] [ProcessesAreRunningAutomationPipelineTrigger.cs#29:IsSatisfiedAsync] Checking for r5apex... [processes=r5apex] [01/11/2022 11:21:34.641] [17] [ProcessesAreRunningAutomationPipelineTrigger.cs#34:IsSatisfiedAsync] Process name r5apex not in the list. ...... [01/11/2022 11:21:52.706] [17] [AbstractWMIListener.cs#84:Handler] Event received. [value=(Stopped, 5740, r5apex.exe), listener=InstanceEventListener] [01/11/2022 11:21:52.707] [17] [ProcessesStopRunningAutomationPipelineTrigger.cs#30:IsSatisfiedAsync] Checking for r5apex... [processes=r5apex] [01/11/2022 11:21:52.707] [17] [ProcessesStopRunningAutomationPipelineTrigger.cs#35:IsSatisfiedAsync] Process name r5apex not in the list. ```
BartoszCichecki commented 2 years ago

LenovoLegionToolkitSetup.zip

Second time is the charm :D

DavisR-GitHub commented 2 years ago

Yesss!

Works now ``` [01/11/2022 11:53:06.767] [17] [AbstractWMIListener.cs#84:Handler] Event received. [value=(Started, 18232, r5apex.exe), listener=InstanceEventListener] [01/11/2022 11:53:06.868] [17] [ProcessAutomationListener.cs#85:InstanceCreationListener_Changed] Can't get process r5apex.exe details, fallback to ID only. [01/11/2022 11:53:06.868] [17] [ProcessesAreRunningAutomationPipelineTrigger.cs#29:IsSatisfiedAsync] Checking for r5apex... [processes=r5apex] [01/11/2022 11:53:06.872] [17] [ProcessesAreRunningAutomationPipelineTrigger.cs#42:IsSatisfiedAsync] Process name r5apex found in process list: True. [01/11/2022 11:53:06.872] [17] [AutomationProcessor.cs#305:ProcessEvent] Processing process event. [process.Name=r5apex, type=Started] ```

Thank you!