If you’re reading this article, you’re most likely interested in trying to enable your keyboard backlight at boot for your Lenovo laptop or ThinkPad. By design, Lenovo has disabled this.

Before continuing, you have to know that you risk burning out the keyboard backlight LEDs by having them lit 24/7.

Installing the dependencies

The solution discussed in this article depends on having Lenovo System Interface Foundation Driver installed. If you are using Lenovo Vantage or Lenovo Commercial Vantage, chances are you may already have it installed. If you don’t know how to check whether Lenovo System Interface Foundation Driver is installed, read this guide by Microsoft.

Research

Interacting with the keyboard

We know the majority of plug-ins for Lenovo System Interface Foundation Driver are installed in ‘C:\ProgramData\Lenovo\ImController\Plugins‘.

We are most interested in the ‘ThinkKeyboardPlugin‘ folder. With a .NET decompiler, we can see the source code of some of these files. We’re going to open:

  • Contract_Keyboard.dll (dependency of Keyboard_Core.dll)
  • Keyboard_Core.dll

As we suspected ‘Keyboard_Core.dll’ contains a class ‘KeyboardControl’ in the ‘Keyboard_Core’ namespace. Here we find a method ‘SetKeyboardBackLightStatus(param1, param2);‘.

If you have an older version of the driver installed, you’ll see this method with only 1 parameter, in which case you will not have to pass ‘null’ invoking this function.

In the references, note there’s a dependency of ‘Contract_Keyboard.dll’.

Take a note of the fact that both are in the x86 folder, so they’re 32-bit libraries.

Where do we hook this?

Ok we’re definitely going to want to execute a script upon starting our ThinkPad, right? But what happens if our machine goes to sleep or goes into hibernation?

By right-clicking the start menu button in Windows 10, we can open ‘Event Viewer‘. Expand ‘Windows Logs‘ in the left hand pane and open ‘System‘.

Now we need to find the ‘Source’ or the event publisher’s name. Put your computer to sleep and hibernation, and find an event that looks like it’s being published every time your ThinkPad wakes up.

There is one indeed, the ‘Source‘ is ‘Power-Troubleshooter‘ which published an event with ‘EventId‘ being ‘1‘.

To keep things easy, we’re going to use Powershell, something changes the way these libraries work, we can quickly re-write our script. We will have to use a 32-bit Powershell as we’re going to invoke 64-bit libraries. The 32-bit Powershell is found in the directory ‘C:\Windows\syswow64\WindowsPowerShell\v1.0\powershell.exe‘.

Writing the script

# Settings
[string]$path = 'C:\ProgramData\Lenovo\ImController\Plugins\ThinkKeyboardPlugin\x86\';
[int]$level = 2; # Backlight level: 0 - Off, 1 - Dim, 2 - On

# Don't modify below
[string]$core = $path + 'Keyboard_Core.dll';
[string]$contract = $path + 'Contract_Keyboard.dll';

Add-Type -Path $core;
Add-Type -Path $contract;

[Keyboard_Core.KeyboardControl]$control =  New-Object -TypeName  'Keyboard_Core.KeyboardControl';

$control.SetKeyboardBackLightStatus($level, $null);

lenovo-powershell/auto-keyboard-backlight.ps1 at main · jonashendrickx/lenovo-powershell · GitHub

Scott Hanselman has written a good article on signing Powershell scripts. You’ll want to do this if you don’t want to set the Powershell execution policy to unrestricted or something else. We’ll want to sign the Powershell script.

Installation of the script

If you want to schedule the script, we’ll need to do this with task scheduler. This will cover:

  • Boot
  • Sleep & wakeup
  • Hibernation & wakeup

To schedule with Task Scheduler:

  1. Click ‘Create Task‘.
  2. Choose ‘Run whether user is logged in or not‘. (Make use sure user that executes script has permissions to run on this machine.)
  3. Add a trigger ‘At startup‘.
  4. Add a trigger ‘On an event‘ if you want to support sleep and hibernation. You’ll need to find the EventID in Windows Event Manager.
    1. Log: ‘System’
    2. Source: ‘Power-Troubleshooter’
    3. EventID: 1
  5. Add an action with ‘Program/script‘ location set to ‘C:\Windows\syswow64\WindowsPowerShell\v1.0\powershell.exe‘ and parameters ‘-File “path\to\script\auto-keyboard-backlight.ps1”