Breaking Change! (Quality fix)
This commit is contained in:
parent
c8db67a695
commit
3465a10361
@ -9,7 +9,6 @@ using System.Drawing;
|
||||
|
||||
namespace CC_Functions.W32
|
||||
{
|
||||
|
||||
public sealed class MouseHook : IDisposable
|
||||
{
|
||||
public void Dispose()
|
||||
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static CC_Functions.W32.Privileges;
|
||||
|
||||
namespace CC_Functions.W32
|
||||
{
|
||||
@ -106,7 +107,7 @@ namespace CC_Functions.W32
|
||||
}
|
||||
else
|
||||
{
|
||||
Privileges.EnablePrivilege(SecurityEntity.SE_SHUTDOWN_NAME);
|
||||
EnablePrivilege(SecurityEntity.SeShutdownPrivilege);
|
||||
ExitWindowsEx((ExitWindows)((uint)mode | (uint)mod), reason);
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CC_Functions.W32
|
||||
{
|
||||
public class Privileges
|
||||
public static class Privileges
|
||||
{
|
||||
public static void EnablePrivilege(SecurityEntity securityEntity)
|
||||
{
|
||||
if (!Enum.IsDefined(typeof(SecurityEntity), securityEntity))
|
||||
throw new InvalidEnumArgumentException("securityEntity", (int)securityEntity, typeof(SecurityEntity));
|
||||
var securityEntityValue = GetSecurityEntityValue(securityEntity);
|
||||
var securityEntityValue = securityEntity.ToString();
|
||||
try
|
||||
{
|
||||
var locallyUniqueIdentifier = new NativeMethods.LUID();
|
||||
@ -67,126 +67,86 @@ namespace CC_Functions.W32
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the security entity value.
|
||||
/// </summary>
|
||||
/// <param name="securityEntity">The security entity.</param>
|
||||
private static string GetSecurityEntityValue(SecurityEntity securityEntity)
|
||||
{
|
||||
switch (securityEntity)
|
||||
{
|
||||
case SecurityEntity.SE_ASSIGNPRIMARYTOKEN_NAME:
|
||||
return "SeAssignPrimaryTokenPrivilege";
|
||||
case SecurityEntity.SE_AUDIT_NAME:
|
||||
return "SeAuditPrivilege";
|
||||
case SecurityEntity.SE_BACKUP_NAME:
|
||||
return "SeBackupPrivilege";
|
||||
case SecurityEntity.SE_CHANGE_NOTIFY_NAME:
|
||||
return "SeChangeNotifyPrivilege";
|
||||
case SecurityEntity.SE_CREATE_GLOBAL_NAME:
|
||||
return "SeCreateGlobalPrivilege";
|
||||
case SecurityEntity.SE_CREATE_PAGEFILE_NAME:
|
||||
return "SeCreatePagefilePrivilege";
|
||||
case SecurityEntity.SE_CREATE_PERMANENT_NAME:
|
||||
return "SeCreatePermanentPrivilege";
|
||||
case SecurityEntity.SE_CREATE_SYMBOLIC_LINK_NAME:
|
||||
return "SeCreateSymbolicLinkPrivilege";
|
||||
case SecurityEntity.SE_CREATE_TOKEN_NAME:
|
||||
return "SeCreateTokenPrivilege";
|
||||
case SecurityEntity.SE_DEBUG_NAME:
|
||||
return "SeDebugPrivilege";
|
||||
case SecurityEntity.SE_ENABLE_DELEGATION_NAME:
|
||||
return "SeEnableDelegationPrivilege";
|
||||
case SecurityEntity.SE_IMPERSONATE_NAME:
|
||||
return "SeImpersonatePrivilege";
|
||||
case SecurityEntity.SE_INC_BASE_PRIORITY_NAME:
|
||||
return "SeIncreaseBasePriorityPrivilege";
|
||||
case SecurityEntity.SE_INCREASE_QUOTA_NAME:
|
||||
return "SeIncreaseQuotaPrivilege";
|
||||
case SecurityEntity.SE_INC_WORKING_SET_NAME:
|
||||
return "SeIncreaseWorkingSetPrivilege";
|
||||
case SecurityEntity.SE_LOAD_DRIVER_NAME:
|
||||
return "SeLoadDriverPrivilege";
|
||||
case SecurityEntity.SE_LOCK_MEMORY_NAME:
|
||||
return "SeLockMemoryPrivilege";
|
||||
case SecurityEntity.SE_MACHINE_ACCOUNT_NAME:
|
||||
return "SeMachineAccountPrivilege";
|
||||
case SecurityEntity.SE_MANAGE_VOLUME_NAME:
|
||||
return "SeManageVolumePrivilege";
|
||||
case SecurityEntity.SE_PROF_SINGLE_PROCESS_NAME:
|
||||
return "SeProfileSingleProcessPrivilege";
|
||||
case SecurityEntity.SE_RELABEL_NAME:
|
||||
return "SeRelabelPrivilege";
|
||||
case SecurityEntity.SE_REMOTE_SHUTDOWN_NAME:
|
||||
return "SeRemoteShutdownPrivilege";
|
||||
case SecurityEntity.SE_RESTORE_NAME:
|
||||
return "SeRestorePrivilege";
|
||||
case SecurityEntity.SE_SECURITY_NAME:
|
||||
return "SeSecurityPrivilege";
|
||||
case SecurityEntity.SE_SHUTDOWN_NAME:
|
||||
return "SeShutdownPrivilege";
|
||||
case SecurityEntity.SE_SYNC_AGENT_NAME:
|
||||
return "SeSyncAgentPrivilege";
|
||||
case SecurityEntity.SE_SYSTEM_ENVIRONMENT_NAME:
|
||||
return "SeSystemEnvironmentPrivilege";
|
||||
case SecurityEntity.SE_SYSTEM_PROFILE_NAME:
|
||||
return "SeSystemProfilePrivilege";
|
||||
case SecurityEntity.SE_SYSTEMTIME_NAME:
|
||||
return "SeSystemtimePrivilege";
|
||||
case SecurityEntity.SE_TAKE_OWNERSHIP_NAME:
|
||||
return "SeTakeOwnershipPrivilege";
|
||||
case SecurityEntity.SE_TCB_NAME:
|
||||
return "SeTcbPrivilege";
|
||||
case SecurityEntity.SE_TIME_ZONE_NAME:
|
||||
return "SeTimeZonePrivilege";
|
||||
case SecurityEntity.SE_TRUSTED_CREDMAN_ACCESS_NAME:
|
||||
return "SeTrustedCredManAccessPrivilege";
|
||||
case SecurityEntity.SE_UNDOCK_NAME:
|
||||
return "SeUndockPrivilege";
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(typeof(SecurityEntity).Name);
|
||||
}
|
||||
}
|
||||
|
||||
public enum SecurityEntity
|
||||
{
|
||||
SE_CREATE_TOKEN_NAME,
|
||||
SE_ASSIGNPRIMARYTOKEN_NAME,
|
||||
SE_LOCK_MEMORY_NAME,
|
||||
SE_INCREASE_QUOTA_NAME,
|
||||
SE_UNSOLICITED_INPUT_NAME,
|
||||
SE_MACHINE_ACCOUNT_NAME,
|
||||
SE_TCB_NAME,
|
||||
SE_SECURITY_NAME,
|
||||
SE_TAKE_OWNERSHIP_NAME,
|
||||
SE_LOAD_DRIVER_NAME,
|
||||
SE_SYSTEM_PROFILE_NAME,
|
||||
SE_SYSTEMTIME_NAME,
|
||||
SE_PROF_SINGLE_PROCESS_NAME,
|
||||
SE_INC_BASE_PRIORITY_NAME,
|
||||
SE_CREATE_PAGEFILE_NAME,
|
||||
SE_CREATE_PERMANENT_NAME,
|
||||
SE_BACKUP_NAME,
|
||||
SE_RESTORE_NAME,
|
||||
SE_SHUTDOWN_NAME,
|
||||
SE_DEBUG_NAME,
|
||||
SE_AUDIT_NAME,
|
||||
SE_SYSTEM_ENVIRONMENT_NAME,
|
||||
SE_CHANGE_NOTIFY_NAME,
|
||||
SE_REMOTE_SHUTDOWN_NAME,
|
||||
SE_UNDOCK_NAME,
|
||||
SE_SYNC_AGENT_NAME,
|
||||
SE_ENABLE_DELEGATION_NAME,
|
||||
SE_MANAGE_VOLUME_NAME,
|
||||
SE_IMPERSONATE_NAME,
|
||||
SE_CREATE_GLOBAL_NAME,
|
||||
SE_CREATE_SYMBOLIC_LINK_NAME,
|
||||
SE_INC_WORKING_SET_NAME,
|
||||
SE_RELABEL_NAME,
|
||||
SE_TIME_ZONE_NAME,
|
||||
SE_TRUSTED_CREDMAN_ACCESS_NAME
|
||||
SeAssignPrimaryTokenPrivilege,
|
||||
SeAuditPrivilege,
|
||||
SeBackupPrivilege,
|
||||
SeChangeNotifyPrivilege,
|
||||
SeCreateGlobalPrivilege,
|
||||
SeCreatePagefilePrivilege,
|
||||
SeCreatePermanentPrivilege,
|
||||
SeCreateSymbolicLinkPrivilege,
|
||||
SeCreateTokenPrivilege,
|
||||
SeDebugPrivilege,
|
||||
SeDelegateSessionUserImpersonatePrivilege,
|
||||
SeEnableDelegationPrivilege,
|
||||
SeImpersonatePrivilege,
|
||||
SeIncreaseBasePriorityPrivilege,
|
||||
SeIncreaseWorkingSetPrivilege,
|
||||
SeIncreaseQuotaPrivilege,
|
||||
SeLoadDriverPrivilege,
|
||||
SeLockMemoryPrivilege,
|
||||
SeMachineAccountPrivilege,
|
||||
SeManageVolumePrivilege,
|
||||
SeProfileSingleProcessPrivilege,
|
||||
SeRelabelPrivilege,
|
||||
SeRemoteShutdownPrivilege,
|
||||
SeRestorePrivilege,
|
||||
SeSecurityPrivilege,
|
||||
SeShutdownPrivilege,
|
||||
SeSyncAgentPrivilege,
|
||||
SeSystemEnvironmentPrivilege,
|
||||
SeSystemProfilePrivilege,
|
||||
SeSystemtimePrivilege,
|
||||
SeTakeOwnershipPrivilege,
|
||||
SeTcbPrivilege,
|
||||
SeTimeZonePrivilege,
|
||||
SeTrustedCredManAccessPrivilege,
|
||||
SeUndockPrivilege,
|
||||
SeUnsolicitedInputPrivilege
|
||||
}
|
||||
|
||||
public enum SecurityEntity2
|
||||
{
|
||||
SE_ASSIGNPRIMARYTOKEN_NAME_TEXT,
|
||||
SE_AUDIT_NAME_TEXT,
|
||||
SE_BACKUP_NAME_TEXT,
|
||||
SE_CHANGE_NOTIFY_NAME_TEXT,
|
||||
SE_CREATE_GLOBAL_NAME_TEXT,
|
||||
SE_CREATE_PAGEFILE_NAME_TEXT,
|
||||
SE_CREATE_PERMANENT_NAME_TEXT,
|
||||
SE_CREATE_SYMBOLIC_LINK_NAME_TEXT,
|
||||
SE_CREATE_TOKEN_NAME_TEXT,
|
||||
SE_DEBUG_NAME_TEXT,
|
||||
SE_DELEGATE_SESSION_USER_IMPERSONATE_NAME_TEXT,
|
||||
SE_ENABLE_DELEGATION_NAME_TEXT,
|
||||
SE_IMPERSONATE_NAME_TEXT,
|
||||
SE_INC_BASE_PRIORITY_NAME_TEXT,
|
||||
SE_INC_WORKING_SET_NAME_TEXT,
|
||||
SE_INCREASE_QUOTA_NAME_TEXT,
|
||||
SE_LOAD_DRIVER_NAME_TEXT,
|
||||
SE_LOCK_MEMORY_NAME_TEXT,
|
||||
SE_MACHINE_ACCOUNT_NAME_TEXT,
|
||||
SE_MANAGE_VOLUME_NAME_TEXT,
|
||||
SE_PROF_SINGLE_PROCESS_NAME_TEXT,
|
||||
SE_RELABEL_NAME_TEXT,
|
||||
SE_REMOTE_SHUTDOWN_NAME_TEXT,
|
||||
SE_RESTORE_NAME_TEXT,
|
||||
SE_SECURITY_NAME_TEXT,
|
||||
SE_SHUTDOWN_NAME_TEXT,
|
||||
SE_SYNC_AGENT_NAME_TEXT,
|
||||
SE_SYSTEM_ENVIRONMENT_NAME_TEXT,
|
||||
SE_SYSTEM_PROFILE_NAME_TEXT,
|
||||
SE_SYSTEMTIME_NAME_TEXT,
|
||||
SE_TAKE_OWNERSHIP_NAME_TEXT,
|
||||
SE_TCB_NAME_TEXT,
|
||||
SE_TIME_ZONE_NAME_TEXT,
|
||||
SE_TRUSTED_CREDMAN_ACCESS_NAME_TEXT,
|
||||
SE_UNDOCK_NAME_TEXT,
|
||||
SE_UNSOLICITED_INPUT_NAME_TEXT
|
||||
}
|
||||
public static SecurityEntity EntityToEntity(SecurityEntity2 entity) => (SecurityEntity)entity;
|
||||
internal static class NativeMethods
|
||||
{
|
||||
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
|
Reference in New Issue
Block a user