Namespace consoleapplication1
{
Class Program
{
Static void main (string [] ARGs)
{
Systeminfo info = new systeminfo ();
Console. writeline (info. pcname );
Console. writeline (info. IIS );
// Console. writeline (info. osversion );
Console. writeline (info. Framework );
Console. Readline ();
}
}
Public class systeminfo
{
// Operating system name
Private string pcname;
Public String pcname
{
Get
{
// Obtain it if the operating system is empty
If (string. isnullorempty (this. pcname ))
{
Registrykey rk;
Rk = registry. localmachine. opensubkey ("SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion ");
This. pcname = rk. getvalue ("productname"). tostring ();
}
Return "Current Operating System:" + this. pcname;
}
}
Private int osversion;
Public int osversion
{
Get
{
If (osversion = 0)
{
Registrykey rk;
Rk = registry. localmachine. opensubkey ("SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion ");
Int. tryparse (rk. getvalue ("currentbuildnumber"). tostring (), out this. osversion );
}
Return this. osversion;
}
}
// IIS Version Number
Private string IIS;
Public String IIS
{
Get
{
// Obtain if IIS is empty
If (string. isnullorempty (this. IIS ))
{
Registrykey key = registry. localmachine. opensubkey (@ "SOFTWARE \ Microsoft \ inetstp ");
This. IIS = "IIS" + key. getvalue ("majorversion"). tostring ();
}
Return "IIS Version:" + this. IIS;
}
}
// Framework Version
Private string framework;
Public String framework
{
Get
{
// Obtain if the Framework version is empty
If (string. isnullorempty (this. Framework ))
{
Version V = environment. version;
If (V! = NULL)
{
This. Framework = V. Major + "." + v. Minor;
}
}
Return "Framework Version: Framework" + this. Framework;
}
}
}
}
How to obtain the current operating system, IIS version, and Framework Version