mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
* Get/SetPriorityClass are now Win32 based again
* SeIncreaseBasePriorityPrivilege is now enabled if present git-svn-id: svn://svn.code.sf.net/p/processhacker/code@1955 21ef857c-d57f-4fe0-8362-d861dc6d29cd
This commit is contained in:
@@ -394,6 +394,16 @@ namespace ProcessHacker.Native.Api
|
||||
CreateIgnoreSystemDefault = 0x80000000
|
||||
}
|
||||
|
||||
public enum ProcessPriorityClassWin32 : int
|
||||
{
|
||||
Idle = 0x40,
|
||||
Normal = 0x20,
|
||||
High = 0x80,
|
||||
RealTime = 0x100,
|
||||
BelowNormal = 0x4000,
|
||||
AboveNormal = 0x8000
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum RedrawWindowFlags
|
||||
{
|
||||
|
||||
@@ -749,11 +749,11 @@ namespace ProcessHacker.Native.Api
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool SetPriorityClass(
|
||||
[In] IntPtr ProcessHandle,
|
||||
[In] int Priority
|
||||
[In] ProcessPriorityClassWin32 Priority
|
||||
);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern ProcessPriority GetPriorityClass(
|
||||
public static extern ProcessPriorityClassWin32 GetPriorityClass(
|
||||
[In] IntPtr ProcessHandle
|
||||
);
|
||||
|
||||
|
||||
@@ -1074,16 +1074,6 @@ namespace ProcessHacker.Native.Api
|
||||
MaxProcessInfoClass
|
||||
}
|
||||
|
||||
public enum ProcessPriority
|
||||
{
|
||||
Idle = 0x40,
|
||||
Normal = 0x20,
|
||||
High = 0x80,
|
||||
RealTime = 0x100,
|
||||
BelowNormal = 0x4000,
|
||||
AboveNormal = 0x8000
|
||||
}
|
||||
|
||||
public enum ProcessPriorityClass : byte
|
||||
{
|
||||
Unknown = 0,
|
||||
|
||||
@@ -1877,44 +1877,42 @@ namespace ProcessHacker.Native.Objects
|
||||
/// <returns>A ProcessPriorityClass enum.</returns>
|
||||
public ProcessPriorityClass GetPriorityClass()
|
||||
{
|
||||
//bugfix Workaround: NtStatus Returns DataTypeMisalignment on x64
|
||||
if (!OSVersion.IsAmd64())
|
||||
switch (Win32.GetPriorityClass(this))
|
||||
{
|
||||
NtStatus status;
|
||||
ProcessPriorityClassStruct priorityClass;
|
||||
int retLength;
|
||||
|
||||
if ((status = Win32.NtQueryInformationProcess(
|
||||
this,
|
||||
ProcessInformationClass.ProcessPriorityClass,
|
||||
out priorityClass,
|
||||
Marshal.SizeOf(typeof(ProcessPriorityClassStruct)),
|
||||
out retLength
|
||||
)) >= NtStatus.Error)
|
||||
Win32.ThrowLastError(status);
|
||||
|
||||
return priorityClass.PriorityClass;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (Win32.GetPriorityClass(this))
|
||||
{
|
||||
case ProcessPriority.AboveNormal:
|
||||
return ProcessPriorityClass.AboveNormal;
|
||||
case ProcessPriority.BelowNormal:
|
||||
return ProcessPriorityClass.BelowNormal;
|
||||
case ProcessPriority.High:
|
||||
return ProcessPriorityClass.High;
|
||||
case ProcessPriority.Idle:
|
||||
return ProcessPriorityClass.Idle;
|
||||
case ProcessPriority.Normal:
|
||||
return ProcessPriorityClass.Normal;
|
||||
case ProcessPriority.RealTime:
|
||||
return ProcessPriorityClass.RealTime;
|
||||
default:
|
||||
return ProcessPriorityClass.Unknown;
|
||||
}
|
||||
case ProcessPriorityClassWin32.AboveNormal:
|
||||
return ProcessPriorityClass.AboveNormal;
|
||||
case ProcessPriorityClassWin32.BelowNormal:
|
||||
return ProcessPriorityClass.BelowNormal;
|
||||
case ProcessPriorityClassWin32.High:
|
||||
return ProcessPriorityClass.High;
|
||||
case ProcessPriorityClassWin32.Idle:
|
||||
return ProcessPriorityClass.Idle;
|
||||
case ProcessPriorityClassWin32.Normal:
|
||||
return ProcessPriorityClass.Normal;
|
||||
case ProcessPriorityClassWin32.RealTime:
|
||||
return ProcessPriorityClass.RealTime;
|
||||
default:
|
||||
Win32.ThrowLastError();
|
||||
// Stupid compiler
|
||||
return ProcessPriorityClass.Unknown;
|
||||
}
|
||||
|
||||
// Datatype misalignment on x64
|
||||
|
||||
//NtStatus status;
|
||||
//ProcessPriorityClassStruct priorityClass;
|
||||
//int retLength;
|
||||
|
||||
//if ((status = Win32.NtQueryInformationProcess(
|
||||
// this,
|
||||
// ProcessInformationClass.ProcessPriorityClass,
|
||||
// out priorityClass,
|
||||
// Marshal.SizeOf(typeof(ProcessPriorityClassStruct)),
|
||||
// out retLength
|
||||
// )) >= NtStatus.Error)
|
||||
// Win32.ThrowLastError(status);
|
||||
|
||||
//return priorityClass.PriorityClass;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2402,19 +2400,49 @@ namespace ProcessHacker.Native.Objects
|
||||
/// <param name="priorityClass">The process' priority class.</param>
|
||||
public void SetPriorityClass(ProcessPriorityClass priorityClass)
|
||||
{
|
||||
NtStatus status;
|
||||
ProcessPriorityClassStruct processPriority;
|
||||
ProcessPriorityClassWin32 pcWin32;
|
||||
|
||||
processPriority.Foreground = false;
|
||||
processPriority.PriorityClass = priorityClass;
|
||||
switch (priorityClass)
|
||||
{
|
||||
case ProcessPriorityClass.AboveNormal:
|
||||
pcWin32 = ProcessPriorityClassWin32.AboveNormal;
|
||||
break;
|
||||
case ProcessPriorityClass.BelowNormal:
|
||||
pcWin32 = ProcessPriorityClassWin32.BelowNormal;
|
||||
break;
|
||||
case ProcessPriorityClass.High:
|
||||
pcWin32 = ProcessPriorityClassWin32.High;
|
||||
break;
|
||||
case ProcessPriorityClass.Idle:
|
||||
pcWin32 = ProcessPriorityClassWin32.Idle;
|
||||
break;
|
||||
case ProcessPriorityClass.Normal:
|
||||
pcWin32 = ProcessPriorityClassWin32.Normal;
|
||||
break;
|
||||
case ProcessPriorityClass.RealTime:
|
||||
pcWin32 = ProcessPriorityClassWin32.RealTime;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("priorityClass");
|
||||
}
|
||||
|
||||
if ((status = Win32.NtSetInformationProcess(
|
||||
this,
|
||||
ProcessInformationClass.ProcessPriorityClass,
|
||||
ref processPriority,
|
||||
Marshal.SizeOf(typeof(ProcessPriorityClassStruct))
|
||||
)) >= NtStatus.Error)
|
||||
Win32.ThrowLastError(status);
|
||||
if (!Win32.SetPriorityClass(this, pcWin32))
|
||||
Win32.ThrowLastError();
|
||||
|
||||
// Datatype misalignment on x64.
|
||||
//NtStatus status;
|
||||
//ProcessPriorityClassStruct processPriority;
|
||||
|
||||
//processPriority.Foreground = false;
|
||||
//processPriority.PriorityClass = priorityClass;
|
||||
|
||||
//if ((status = Win32.NtSetInformationProcess(
|
||||
// this,
|
||||
// ProcessInformationClass.ProcessPriorityClass,
|
||||
// ref processPriority,
|
||||
// Marshal.SizeOf(typeof(ProcessPriorityClassStruct))
|
||||
// )) >= NtStatus.Error)
|
||||
// Win32.ThrowLastError(status);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -198,9 +198,9 @@ namespace ProcessHacker
|
||||
{
|
||||
try { thandle.SetPrivilege("SeDebugPrivilege", SePrivilegeAttributes.Enabled); }
|
||||
catch { }
|
||||
try { thandle.SetPrivilege("SeLoadDriverPrivilege", SePrivilegeAttributes.Enabled); }
|
||||
try { thandle.SetPrivilege("SeIncreaseBasePriorityPrivilege", SePrivilegeAttributes.Enabled); }
|
||||
catch { }
|
||||
try { thandle.SetPrivilege("SeSecurityPrivilege", SePrivilegeAttributes.Enabled); }
|
||||
try { thandle.SetPrivilege("SeLoadDriverPrivilege", SePrivilegeAttributes.Enabled); }
|
||||
catch { }
|
||||
try { thandle.SetPrivilege("SeShutdownPrivilege", SePrivilegeAttributes.Enabled); }
|
||||
catch { }
|
||||
|
||||
Reference in New Issue
Block a user