Skip to content

Instantly share code, notes, and snippets.

@nanoant
Created June 28, 2020 14:55
Show Gist options
  • Save nanoant/a69478b170408bd1859c30631d828c60 to your computer and use it in GitHub Desktop.
Save nanoant/a69478b170408bd1859c30631d828c60 to your computer and use it in GitHub Desktop.
Simple service that whitelists nvcontainer process responsible for XBOX controller emulation for NVIDIA Shield Controller
//
// Simple service that whitelists nvcontainer process responsible for XBOX controller emulation for NVIDIA Shield Controller
//
// Copyright (c) 2020 Adam Strzelecki
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// Usage:
//
// C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe .\HidGuardianHelper.cs
// New-Service -Name HidGuardianHelper -DependsOn NvContainerLocalSystem -BinaryPathName $PWD\HidGuardianHelper.exe -DisplayName HidGuardianHelper -Description "HID Guardian Helper Service" -StartupType Automatic
// Start-Service HidGuardianHelper
// sc.exe delete HidGuardianHelper
// ls HKLM:\SYSTEM\CurrentControlSet\Services\HidGuardian\Parameters\Whitelist
using System;
using System.ServiceProcess;
using System.Diagnostics;
using Microsoft.Win32;
namespace HidGuardian {
public partial class Service: ServiceBase {
protected override void OnStart(string[] args) {
base.OnStart(args);
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\HidGuardian\Parameters\Whitelist", true)) {
foreach(string subKeyName in key.GetSubKeyNames()) {
key.DeleteSubKeyTree(subKeyName);
}
foreach (Process process in Process.GetProcessesByName("nvcontainer")) {
key.CreateSubKey(process.Id.ToString());
}
}
}
}
static class Program {
static void Main() {
ServiceBase.Run(new ServiceBase[] { new Service() } );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment