Hello guys,

This is my last resort... I'm trying to get the value of Peak Commit Charge on a win xp 32 machine.
I've searched and searched but the only ways to get this info are in PowerShell and Python.
In either case I can't produce an acceptable sized exe. I need to run it on remote computers without installing PowerShell or Python on 200+ machines.

So the solution as I see it is to compile an simple c# code that return that value.

The ps1 and py scripts look basically the same, I've tried, unsuccessfully, to find a c# code. I have to confess I'm a total newbie when it comes to c#.

Could anyone look over the following pwershell script and "translate" it into c# code from witch I could build an .exe with an online c# compiler...

Thank a lot.

$sig = @'
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_PERFORMANCE_INFORMATION {
public Int64 IdleTime;
public Int64 ReadTransferCount;
public Int64 WriteTransferCount;
public Int64 OtherTransferCount;
public uint ReadOperationCount;
public uint WriteOperationCount;
public uint OtherOperationCount;
public uint AvailablePages;
public uint TotalCommittedPages;
public uint TotalCommitLimit;
public uint PeakCommitment;
public uint PageFaults;
public uint WriteCopyFaults;
public uint TransitionFaults;
public uint Reserved1;
public uint DemandZeroFaults;
public uint PagesRead;
public uint PageReadIos;
public ulong Reserved2;
public uint PagefilePagesWritten;
public uint PagefilePageWriteIos;
public uint MappedFilePagesWritten;
public uint MappedFilePageWriteIos;
public uint PagedPoolUsage;
public uint NonPagedPoolUsage;
public uint PagedPoolAllocs;
public uint PagedPoolFrees;
public uint NonPagedPoolAllocs;
public uint NonPagedPoolFrees;
public uint TotalFreeSystemPtes;
public uint SystemCodePage;
public uint TotalSystemDriverPages;
public uint TotalSystemCodePages;
public uint SmallNonPagedLookasideListAllocateHits;
public uint SmallPagedLookasideListAllocateHits;
public uint Reserved3;
public uint MmSystemCachePage;
public uint PagedPoolPage;
public uint SystemDriverPage;
public uint FastReadNoWait;
public uint FastReadWait;
public uint FastReadResourceMiss;
public uint FastReadNotPossible;
public uint FastMdlReadNoWait;
public uint FastMdlReadWait;
public uint FastMdlReadResourceMiss;
public uint FastMdlReadNotPossible;
public uint MapDataNoWait;
public uint MapDataWait;
public uint MapDataNoWaitMiss;
public uint MapDataWaitMiss;
public uint PinMappedDataCount;
public uint PinReadNoWait;
public uint PinReadWait;
public uint PinReadNoWaitMiss;
public uint PinReadWaitMiss;
public uint CopyReadNoWait;
public uint CopyReadWait;
public uint CopyReadNoWaitMiss;
public uint CopyReadWaitMiss;
public uint MdlReadNoWait;
public uint MdlReadWait;
public uint MdlReadNoWaitMiss;
public uint MdlReadWaitMiss;
public uint ReadAheadIos;
public uint LazyWriteIos;
public uint LazyWritePages;
public uint DataFlushes;
public uint DataPages;
public uint ContextSwitches;
public uint FirstLevelTbFills;
public uint SecondLevelTbFills;
public uint SystemCalls;
}

[DllImport("ntdll.dll")]
public static extern int NtQuerySystemInformation(
uint SYSTEM_INFORMATION_CLASS,
ref SYSTEM_PERFORMANCE_INFORMATION returnStruct,
uint length,
ref uint returnLength);
'@

Add-Type -MemberDefinition $sig -Name NTDLL -Namespace Win32 > $null

$out = New-Object Win32.NTDLL+SYSTEM_PERFORMANCE_INFORMATION
$outlen = New-Object int

[Win32.NTDLL]::NtQuerySystemInformation(2, [ref]$out, [System.Runtime.InteropServices.Marshal]::SizeOf($out), [ref]$outlen) > $null
return $out.PeakCommitment * 4096 /1024