<%@ Page Language="C#" AutoEventWireup="true" CodeFile="getingOSversion.aspx.cs" Inherits="getingOSversion" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<br />
TotalPageFileSpace<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<br />
TotalPhysicalMemory<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />
<br />
TotalVirtualMemory<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
<br />
<br />
AvailableVirtualMemory<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
<br />
<br />
csname<asp:Label ID="Label7" runat="server" Text="Label"></asp:Label>
<br />
<br />
WindowsDirectory<asp:Label ID="Label8" runat="server" Text="Label"></asp:Label>
<br />
<br />
Manufacturer<asp:Label ID="Label9" runat="server" Text="Label"></asp:Label>
<br />
<br />
operating system:<asp:Label ID="Label10" runat="server" Text="Label"></asp:Label>
<br />
<br />
Version:<asp:Label ID="Label11" runat="server" Text="Label"></asp:Label>
<br />
<br />
<br />
<asp:GridView ID="gv_id" runat="server"></asp:GridView>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Management;
using System.Data;
public partial class getingOSversion : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
memoryinfo_form();
diskinfo_form();
}
private void diskinfo_form()
{
ConnectionOptions options = new ConnectionOptions();
ManagementScope scope = new ManagementScope("\\\\localhost\\root\\cimv2",
options);
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
SelectQuery query1 = new SelectQuery("Select * from Win32_LogicalDisk");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(scope, query1);
ManagementObjectCollection queryCollection1 = searcher1.Get();
foreach (ManagementObject m in queryCollection)
{
// Display the remote computer information
Label7.Text = m["csname"].ToString();
Label8.Text = m["WindowsDirectory"].ToString();
Label10.Text = m["Caption"].ToString();
Label11.Text = m["Version"].ToString();
Label9.Text = m["Manufacturer"].ToString();
}
DataTable dt = new DataTable();
dt.Columns.Add("Diskname");
dt.Columns.Add("Disksize");
dt.Columns.Add("freespace");
dt.Columns.Add("DiviseId");
dt.Columns.Add("volumename");
dt.Columns.Add("systemname");
dt.Columns.Add("VolumeSerialNumber");
foreach (ManagementObject mo in queryCollection1)
{
DataRow dr = dt.NewRow();
dr[0] = mo["Name"];
dr[1] = mo["Size"];
dr[2] = mo["FreeSpace"];
dr[3] = mo["DeviceID"];
dr[4] = mo["VolumeName"];
dr[5] = mo["SystemName"];
dr[6] = mo["VolumeSerialNumber"];
dt.Rows.Add(dr);
gv_id.DataSource = dt;
gv_id.DataBind();
}
}
private void memoryinfo_form()
{
ObjectQuery winQuery = new ObjectQuery("SELECT * FROM Win32_LogicalMemoryConfiguration");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(winQuery);
foreach (ManagementObject item in searcher.Get())
{
Label2.Text = item["TotalPageFileSpace"].ToString();
Label3.Text = item["TotalPhysicalMemory"].ToString();
Label4.Text = item["TotalVirtualMemory"].ToString();
Label5.Text = item["AvailableVirtualMemory"].ToString();
}
}
}
No comments:
Post a Comment