If you have a wireless XBox controller for PC, then you cannot turn the controller off without removing-and-reattaching the battery pack. Further, if you shut your computer off, the XBox controller will keep trying to find the wireless receiver until it drains the battery.
This project is a ‘shutdown’ script which you can use;
- Set it as a shutdown script so that it always turns the XBox controller off when turning your PC off
- Call it directly to turn the XBox controller off
Setup
To set it in your shutdown,
Click Start > Run…
gpedit.msc
Go to startup/shutdown scripts:
Under the scripts tab, add the powershell script (adding to the PowerShell tab didn’t work for me, I used this tab instead):
Or add the EXE directly:
Apply and close.
Finally, Start > Run…
gpupdate /force
How it works
This script makes use of an undocumented feature of xinput1_3.dll
.
These methods, along with their ordinals are:
# 100:
DWORD XInputGetStateEx(DWORD dwUserIndex, XINPUT_STATE *pState);
# 101:
DWORD XInputWaitForGuideButton(DWORD dwUserIndex, DWORD dwFlag, unKnown *pUnKnown);
# 102:
DWORD XInputCancelGuideButtonWait(DWORD dwUserIndex);
# 103:
DWORD XInputPowerOffController(DWORD dwUserIndex);
The script or executable simply invoke ordinal 103 with the index of the XBox controller.
[DllImport("XInput1_3.dll", CharSet = CharSet.Auto, EntryPoint = "#103")]
internal static extern int FnOff(int i);
And then invoking FnOff(0)
To turn off multiple controllers you would simply invoke FnOff(1)
and 2 and so on.