Bởi vì vấn đề chúng ta đang gặp phải liên quan đến MS KB 976618 và do không muốn chạy mã nhị phân từ các bên thứ ba không xác định trên các máy chủ sản xuất, tôi bị buộc phải sử dụng ngôn ngữ C#. Bởi vì tôi là một newb tại C# nó đã cho tôi một thời gian nhưng cuối cùng tôi đã tìm ra các bit phụ xung quanh đoạn mã người đã được đăng. Vì vậy, đầy đủ ms visual studio C# console chương trình của tôi rằng biên dịch và chạy là:
using System;
using System.Runtime.InteropServices;
class Program
{
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool GetSystemFileCacheSize(
ref IntPtr lpMinimumFileCacheSize,
ref IntPtr lpMaximumFileCacheSize,
ref IntPtr lpFlags
);
static void Main(string[] args)
{
IntPtr lpMinimumFileCacheSize = IntPtr.Zero;
IntPtr lpMaximumFileCacheSize = IntPtr.Zero;
IntPtr lpFlags = IntPtr.Zero;
bool b = GetSystemFileCacheSize(ref lpMinimumFileCacheSize, ref lpMaximumFileCacheSize, ref lpFlags);
Console.WriteLine(b);
Console.WriteLine(lpMinimumFileCacheSize);
Console.WriteLine(lpMaximumFileCacheSize);
Console.WriteLine(lpFlags);
}
}
và trên Windows 7 x64 máy tính của tôi nó ra
True
1048576
1099511627776
0
và không, đó không phải là máy chủ sản xuất của chúng tôi.
và sau đó trong PowerShell đây là
$source = @"
using System;
using System.Runtime.InteropServices;
namespace MyTools
{
public static class cache
{
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool GetSystemFileCacheSize(
ref IntPtr lpMinimumFileCacheSize,
ref IntPtr lpMaximumFileCacheSize,
ref IntPtr lpFlags
);
public static bool Get(ref IntPtr a, ref IntPtr c, ref IntPtr d)
{
IntPtr lpMinimumFileCacheSize = IntPtr.Zero;
IntPtr lpMaximumFileCacheSize = IntPtr.Zero;
IntPtr lpFlags = IntPtr.Zero;
bool b = GetSystemFileCacheSize(ref lpMinimumFileCacheSize, ref lpMaximumFileCacheSize, ref lpFlags);
a = lpMinimumFileCacheSize;
c = lpMaximumFileCacheSize;
d = lpFlags;
return b;
}
}
}
"@
Add-Type -TypeDefinition $source -Language CSharp
# Init variables
$SFCMin = 0
$SFCMax = 0
$SFCFlags = 0
$b = [MyTools.cache]::Get([ref]$SFCMin, [ref]$SFCMax, [ref]$SFCFlags)
#typecast values so we can do some math with them
$SFCMin = [long]$SFCMin
$SFCMax = [long]$SFCMax
$SFCFlags = [long]$SFCFlags
write-output "Return values from GetSystemFileCacheSize are: "
write-output "Function Result : $b"
write-output " Min : $SFCMin"
write-output (" Max : $SFCMax (" + $SFCMax/1024/1024/1024 + " GiB)")
write-output " Flags : $SFCFlags"
Bước tiếp theo: SetSystemFileCacheSize, tôi đã viết một kịch bản PowerShell cho điều này và đặt nó trên https://serverfault.com/questions/325277/windows-server-2008-r2-metafile-ram-usage/527466#527466
Tôi ngạc nhiên không có một ví dụ về http://pinvoke.net cho chức năng đó. (vào menu phụ Kernel32.dll). Nếu bạn nhận được nó làm việc, xin vui lòng thêm một ví dụ cho trang web đó (nó là một wiki). –
Bạn đã thử gọi GetLastWin32Error sau đó để nhận lỗi? –
xin lỗi - Tôi là một dope hoàn chỉnh, tôi đã có nền tảng đích vẫn được đặt thành X86. Bây giờ tôi cảm thấy xấu hổ. Sau khi thiết lập cho bất kỳ CPU nó hoạt động tốt. – Johnv2020