Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions PCL.Core/Utils/OS/NtInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -64,7 +64,7 @@ public static Version GetCurrentOsVersion()
/// <returns>返回原来相应特权的状态。</returns>
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;
}
Expand All @@ -74,4 +74,4 @@ public static void SetSystemInformation(SystemInformationClass infoClass, IntPtr
var result = NtSetSystemInformation(infoClass, info, infoLength);
if (result != 0) _ThrowLastWin32Error((int)RtlNtStatusToDosError(result));
}
}
}
19 changes: 9 additions & 10 deletions Plain Craft Launcher 2/Pages/PageTools/PageToolsTest.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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)
Expand Down