Sign in to follow this  
  • entries
    16
  • comments
    42
  • views
    9457

Nothin' much.

Sign in to follow this  
takingsometime

288 views

Not much has been going on lately, but I keep getting the feeling that I should update this journal more often.

I'm still waiting on my thesis results (I've got the examiners reports, and I'm very happy), but I have to wait for them to pass through the University's bureaucracy before I can say much. I'm also still waiting on news of the job at the University. It's been nearly 4 months, and the selection process in still ongoing [headshake].

I've completely converted to C# now, and going back to C++ makes me feel all dirty. I'll still need to use it for various time comparisons with old code though. While coding the logging system of a new project, I noticed that there wasn't much info around for getting system information with C#. I've cobbled together most of what I needed (no real networking stuff), and thought I'd share in case someone else needs/wants it.


using System;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using Microsoft.Win32;


namespace SysInfo
{
public class SysInfo
{
#region Native Methods

[StructLayout(LayoutKind.Sequential)]
public struct MemoryStatus
{
public uint dwLength;
public uint dwMemoryLoad;
public uint dwTotalPhys;
public uint dwAvailPhys;
public uint dwTotalPageFile;
public uint dwAvailPageFile;
public uint dwTotalVirtual;
public uint dwAvailVirtual;
}
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern void GlobalMemoryStatus(ref MemoryStatus ms);

#endregion

public struct ProcessorInfo
{
public string ProcessorName;
public string ProcessorDescription;
public int ProcessorSpeed;
}

#region Members

private MemoryStatus ms = new MemoryStatus();
private ProcessorInfo[] processorinfo;
private DriveInfo[] driveinfo;

#endregion

#region Properties

public string OperatingSystem
{
get { return System.Environment.OSVersion.VersionString; }
}
public string ServicePack
{
get { return System.Environment.OSVersion.ServicePack; }
}
public Version OperatingSystemVersion
{
get { return System.Environment.OSVersion.Version; }
}
public Version CLRVersion
{
get { return System.Environment.Version; }
}

public string SystemDirectory
{
get { return System.Environment.SystemDirectory; }
}
public string CurrentDirectory
{
get { return System.Environment.CurrentDirectory; }
}

public string UserName
{
get { return System.Environment.UserName; }
}
public string UserDomainName
{
get { return System.Environment.UserDomainName; }
}
public string NetBIOSName
{
get { return System.Environment.MachineName; }
}

public long WorkingSet
{
get { return System.Environment.WorkingSet; }
}
public int NumberOfProcessors
{
get { return System.Environment.ProcessorCount; }
}

public ProcessorInfo[] ProcessorInformation
{
get { return processorinfo; }
}

public long TotalPhysicalMemory
{
get { return ms.dwTotalPhys; }
}
public long TotalVirtualMemory
{
get { return ms.dwTotalVirtual; }
}
public long TotalPageFile
{
get { return ms.dwTotalPageFile; }
}
public long AvailablePhysicalMemory
{
get { return ms.dwAvailPhys; }
}
public long AvailableVirtualMemory
{
get { return ms.dwAvailVirtual; }
}
public long AvailablePageFile
{
get { return ms.dwAvailPageFile; }
}
public long PercentageAvailableMemory
{
get { return ms.dwMemoryLoad; }
}

public DriveInfo[] DriveInformation
{
get { return driveinfo; }
}

public string HostName
{
get { return Dns.GetHostName();}
}
public string HostIPAddress
{
get { return Dns.GetHostAddresses(Dns.GetHostName())[0].ToString(); }
}

#endregion

#region Methods

public SysInfo()
{
GlobalMemoryStatus(ref ms);

processorinfo = new ProcessorInfo[System.Environment.ProcessorCount];
for (int i = 0; i < System.Environment.ProcessorCount; i++)
{
string sKeyPath = @"HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\SYSTEM\CentralProcessor\" + i;
processorinfo.ProcessorName = ReadRegistryObject(sKeyPath, "ProcessorNameString").ToString();
processorinfo.ProcessorDescription = ReadRegistryObject(sKeyPath, "Identifier").ToString();
processorinfo.ProcessorSpeed = (int)ReadRegistryObject(sKeyPath, "~MHz");
}

driveinfo = DriveInfo.GetDrives();
}

public void QueryStatus()
{
GlobalMemoryStatus(ref ms);
driveinfo = DriveInfo.GetDrives();
}

private object ReadRegistryObject(string sKeyPath, string sKey)
{
object o = Registry.GetValue(sKeyPath, sKey, null);
return o;
}

#endregion
}
}



A demo project can be downloaded from here.



I do have a new project in the works, but unfortunately it doesn't fit in with the 4E contest (why couldn't the elements include bad 80's TV shows, programmer art, and system crashing bugs?). I'll post some 'concept art' from this project soon.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now