Jump to content

Recommended Posts

Posted

So I'm writing this little app in .NET, but I'm having some troubles getting the Operating System type. I can already get the OS version (Windows 2000/XP, etc), but I need to get Home/Pro etc.


System.OperatingSystem osInfo = System.Environment.OSVersion;
string windowsVersion = "Windows Version: ";
int servicePack = 0;

// Determine the platform.
switch (osInfo.Platform)
{
case System.PlatformID.Win32Windows:
MessageBox.Show("This program is not supported on this version of Windows.");
System.Environment.Exit(0);
break;

case System.PlatformID.Win32NT:

switch (osInfo.Version.Major)
{
case 3:
case 4:
MessageBox.Show("This program is not supported on this version of Windows.");
System.Environment.Exit(0);
break;
case 5:
if (osInfo.Version.Minor == 0)
{
windowsVersion += "Windows 2000";
windowsVersion += osInfo.ServicePack.ToString();
MessageBox.Show("Windows 2000");
}
else
{
windowsVersion += "Windows XP ";
OSVERSIONINFOEX osVersion = new OSVERSIONINFOEX();
GlobalFunctions.GetVersionEx(osVersion);
switch(osVersion.SuiteMask)
{
case 0x00000200:
windowsVersion += "Home Edition ";
break;
default:
windowsVersion += "Professional ";
break;
}
switch (osInfo.ServicePack)
{
case "Service Pack 2":
windowsVersion += "Service Pack 2";
servicePack = 2;
break;
case "Service Pack 1":
windowsVersion += "Service Pack 1";
servicePack = 1;
break;
}
}
break;
} break;
}

I'm importing the GetVersionEx function from kernel32.dll. I'm guessing the problem comes from the enumerated data types that aren't properly passed over...

Any ideas?


Posted

Thanks GSM - that's pretty much exactly what I want. I just don't know how to turn that VB.NET code into C#.NET... :P

The My namespace doesn't exist in .NET, and I've yet to find an equivalent. That's why I moved towards importing the API import (as per jcarle's suggestion over MSN).

EDIT - I think I got it actually... I sent a spoof program that just spits out information to a friend of mine, and got him to send me back the info. :)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...