NetStatisticsGet (netapi32)
Last changed: drake@cdrake.net-153.23.1.60

.
Summary
Retrieves operating statistics for a service. Currently, only the workstation and server services are supported.

C# Signature:

[DllImport("Netapi32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
    private extern static int NetStatisticsGet(
        [MarshalAs(UnmanagedType.LPWStr)] string serverName,
        [MarshalAs(UnmanagedType.LPWStr)] string service,
        int level,
        int options,
        out IntPtr BufPtr);

VB Signature:

Declare Function NetStatisticsGet Lib "Netapi32.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

//
//I found the following at http://www.codeproject.com/KB/cs/GetLastRebootTime.aspx by Gautham Jayaraman
//

static void Main(string[] args)

{

IntPtr bufPtr = IntPtr.Zero;
int val = NetStatisticsGet(null, "LanmanWorkstation", 0, 0, out bufPtr);
// see STAT_WORKSTATION_0 under structures http://pinvoke.net/default.aspx/Structures.STAT_WORKSTATION_0
STAT_WORKSTATION_0 wks = new STAT_WORKSTATION_0();
if (val == 0)
{
    wks = (STAT_WORKSTATION_0)Marshal.PtrToStructure(bufPtr, typeof(STAT_WORKSTATION_0));
}
DateTime aRebootTime = DateTime.FromFileTime(wks.StatisticsStartTime);
System.Console.WriteLine(aRebootTime);

}

Documentation