diff --git a/DS4Windows/DS4Control/Util.cs b/DS4Windows/DS4Control/Util.cs new file mode 100644 index 0000000..b749af1 --- /dev/null +++ b/DS4Windows/DS4Control/Util.cs @@ -0,0 +1,67 @@ +using System; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; + +namespace DS4Windows +{ + [SuppressUnmanagedCodeSecurity] + class Util + { + public enum PROCESS_INFORMATION_CLASS : int + { + ProcessBasicInformation = 0, + ProcessQuotaLimits, + ProcessIoCounters, + ProcessVmCounters, + ProcessTimes, + ProcessBasePriority, + ProcessRaisePriority, + ProcessDebugPort, + ProcessExceptionPort, + ProcessAccessToken, + ProcessLdtInformation, + ProcessLdtSize, + ProcessDefaultHardErrorMode, + ProcessIoPortHandlers, + ProcessPooledUsageAndLimits, + ProcessWorkingSetWatch, + ProcessUserModeIOPL, + ProcessEnableAlignmentFaultFixup, + ProcessPriorityClass, + ProcessWx86Information, + ProcessHandleCount, + ProcessAffinityMask, + ProcessPriorityBoost, + ProcessDeviceMap, + ProcessSessionInformation, + ProcessForegroundInformation, + ProcessWow64Information, + ProcessImageFileName, + ProcessLUIDDeviceMapsEnabled, + ProcessBreakOnTermination, + ProcessDebugObjectHandle, + ProcessDebugFlags, + ProcessHandleTracing, + ProcessIoPriority, + ProcessExecuteFlags, + ProcessResourceManagement, + ProcessCookie, + ProcessImageInformation, + ProcessCycleTime, + ProcessPagePriority, + ProcessInstrumentationCallback, + ProcessThreadStackAllocation, + ProcessWorkingSetWatchEx, + ProcessImageFileNameWin32, + ProcessImageFileMapping, + ProcessAffinityUpdateMode, + ProcessMemoryAllocationMode, + MaxProcessInfoClass + } + + [DllImport("ntdll.dll", SetLastError = true)] + public static extern int NtSetInformationProcess(IntPtr processHandle, + PROCESS_INFORMATION_CLASS processInformationClass, ref IntPtr processInformation, uint processInformationLength); + } +} diff --git a/DS4Windows/DS4Windows.csproj b/DS4Windows/DS4Windows.csproj index a573484..9dfc9ed 100644 --- a/DS4Windows/DS4Windows.csproj +++ b/DS4Windows/DS4Windows.csproj @@ -141,6 +141,7 @@ + UserControl diff --git a/DS4Windows/Program.cs b/DS4Windows/Program.cs index c5045d3..1adf387 100644 --- a/DS4Windows/Program.cs +++ b/DS4Windows/Program.cs @@ -75,6 +75,16 @@ namespace DS4Windows } catch { } // Ignore problems raising the priority. + // Force Normal IO Priority + IntPtr ioPrio = new IntPtr(2); + Util.NtSetInformationProcess(Process.GetCurrentProcess().Handle, + Util.PROCESS_INFORMATION_CLASS.ProcessIoPriority, ref ioPrio, 4); + + // Force Normal Page Priority + IntPtr pagePrio = new IntPtr(5); + Util.NtSetInformationProcess(Process.GetCurrentProcess().Handle, + Util.PROCESS_INFORMATION_CLASS.ProcessPagePriority, ref pagePrio, 4); + try { // another instance is already running if OpenExsting succeeds.