diff --git a/PCL.Core/Utils/OS/NtInterop.cs b/PCL.Core/Utils/OS/NtInterop.cs index aebd1315e..7ce4c7d95 100644 --- a/PCL.Core/Utils/OS/NtInterop.cs +++ b/PCL.Core/Utils/OS/NtInterop.cs @@ -15,9 +15,9 @@ private static partial void RtlGetNtVersionNumbers( [LibraryImport("ntdll.dll")] private static partial uint RtlAdjustPrivilege( SePrivilege privilege, - [MarshalAs(UnmanagedType.Bool)] bool enable, - [MarshalAs(UnmanagedType.Bool)] bool currentThread, - [MarshalAs(UnmanagedType.Bool)] out bool enabled); + [MarshalAs(UnmanagedType.U1)] bool enable, + [MarshalAs(UnmanagedType.U1)] bool currentThread, + [MarshalAs(UnmanagedType.U1)] out bool enabled); [LibraryImport("ntdll.dll")] private static partial ulong RtlNtStatusToDosError(uint status); @@ -64,7 +64,7 @@ public static Version GetCurrentOsVersion() /// 返回原来相应特权的状态。 public static bool SetPrivilege(SePrivilege privilege, bool state, bool currentThread = true) { - var result = RtlAdjustPrivilege(privilege, false, currentThread, out var enabled); + var result = RtlAdjustPrivilege(privilege, state, currentThread, out var enabled); if (result != 0) _ThrowLastWin32Error((int)RtlNtStatusToDosError(result)); return enabled; } @@ -74,4 +74,4 @@ public static void SetSystemInformation(SystemInformationClass infoClass, IntPtr var result = NtSetSystemInformation(infoClass, info, infoLength); if (result != 0) _ThrowLastWin32Error((int)RtlNtStatusToDosError(result)); } -} \ No newline at end of file +} diff --git a/Plain Craft Launcher 2/Pages/PageTools/PageToolsTest.xaml.vb b/Plain Craft Launcher 2/Pages/PageTools/PageToolsTest.xaml.vb index d367d6e9e..6ba6c401a 100644 --- a/Plain Craft Launcher 2/Pages/PageTools/PageToolsTest.xaml.vb +++ b/Plain Craft Launcher 2/Pages/PageTools/PageToolsTest.xaml.vb @@ -324,8 +324,8 @@ Public Class PageToolsTest '提权部分 Try - NtInterop.SetPrivilege(NtInterop.SePrivilege.SeProfileSingleProcessPrivilege, True) - NtInterop.SetPrivilege(NtInterop.SePrivilege.SeIncreaseQuotaPrivilege, True) + NtInterop.SetPrivilege(NtInterop.SePrivilege.SeProfileSingleProcessPrivilege, True, False) + NtInterop.SetPrivilege(NtInterop.SePrivilege.SeIncreaseQuotaPrivilege, True, False) Catch ex As System.ComponentModel.Win32Exception Throw New Exception(String.Format("获取内存优化权限失败(错误代码:{0})", ex.NativeErrorCode)) End Try @@ -338,7 +338,6 @@ Public Class PageToolsTest Dim NowType = "None" Try Dim info As Integer - Dim scfi As SYSTEM_FILECACHE_INFORMATION Dim combineInfoEx As MEMORY_COMBINE_INFORMATION_EX Dim _gcHandle As GCHandle @@ -348,13 +347,13 @@ Public Class PageToolsTest NtInterop.SetSystemInformation(NtInterop.SystemInformationClass.SystemMemoryListInformation, _gcHandle.AddrOfPinnedObject(), Marshal.SizeOf(info)) _gcHandle.Free() - NowType = "SystemFileCacheInformation" - scfi.MaximumWorkingSet = UInteger.MaxValue - scfi.MinimumWorkingSet = UInteger.MaxValue - _gcHandle = GCHandle.Alloc(scfi, GCHandleType.Pinned) - NtInterop.SetSystemInformation(NtInterop.SystemInformationClass.SystemFileCacheInformationEx, - _gcHandle.AddrOfPinnedObject(), Marshal.SizeOf(scfi)) - _gcHandle.Free() + 'NowType = "SystemFileCacheInformation" + 'scfi.MaximumWorkingSet = UInteger.MaxValue + 'scfi.MinimumWorkingSet = UInteger.MaxValue + '_gcHandle = GCHandle.Alloc(scfi, GCHandleType.Pinned) + 'NtInterop.SetSystemInformation(NtInterop.SystemInformationClass.SystemFileCacheInformationEx, + ' _gcHandle.AddrOfPinnedObject(), Marshal.SizeOf(scfi)) + '_gcHandle.Free() NowType = "MemoryFlushModifiedList" info = 3 _gcHandle = GCHandle.Alloc(info, GCHandleType.Pinned)