0% found this document useful (0 votes)
38 views

Operating Sys Source Code

This document defines a C# program that connects to a remote machine, queries the operating system and processor information using WMI, and displays key details about the operating system, memory, and CPU usage. It creates a ManagementScope connected to a remote machine, executes WMI queries to retrieve data from the Win32_OperatingSystem and Win32_PerfFormattedData_Counters_ProcessorInformation classes, and loops through and prints the results, including computer name, OS details, memory information, and CPU usage percentage.

Uploaded by

Rudresh CM
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Operating Sys Source Code

This document defines a C# program that connects to a remote machine, queries the operating system and processor information using WMI, and displays key details about the operating system, memory, and CPU usage. It creates a ManagementScope connected to a remote machine, executes WMI queries to retrieve data from the Win32_OperatingSystem and Win32_PerfFormattedData_Counters_ProcessorInformation classes, and loops through and prints the results, including computer name, OS details, memory information, and CPU usage percentage.

Uploaded by

Rudresh CM
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Management;
namespace operating_sys
{
class Program
{
public static void Main()
{
ConnectionOptions connection = new ConnectionOptions();
connection.Username = "kushi";
connection.Password = "kushi888";
connection.Authority = "ntlmdomain:DOMAIN";
ManagementScope ms = new ManagementScope("\\\\KUSHI-PC\\root\\CIMV2",
connection);
ms.Connect();
System.Management.SelectQuery sq = new System.Management.SelectQuery("SELECT *
FROM Win32_OperatingSystem");
System.Management.ManagementObjectSearcher mos = new
System.Management.ManagementObjectSearcher(ms, sq);
foreach (System.Management.ManagementObject m in mos.Get())
{
Console.WriteLine("Computer Name : {0}",
m["csname"]);
Console.WriteLine("Windows Directory : {0}",
m["WindowsDirectory"]);
Console.WriteLine("Operating System: {0}",
m["Caption"]);
Console.WriteLine("Version: {0}", m["Version"]);
Console.WriteLine("Manufacturer : {0}",
m["Manufacturer"]);
Console.WriteLine("Free Physical Memory : {0}",
m["FreePhysicalMemory"]);
Console.WriteLine("Free Virual Memory : {0}",
m["FreeVirtualMemory"]);
Console.WriteLine("Total Virtual Memory Size : {0}",
m["TotalVirtualMemorySize"]);
Console.WriteLine("Total Visible Memory Size : {0}",
m["TotalVisibleMemorySize"]);
Console.WriteLine("Free Physical Memory : {0}",
m["FreePhysicalMemory"]);

//Console.WriteLine("CPU Usage : {0}",


// m["TotalCPUUsage"]);

System.Management.SelectQuery sq1 = new System.Management.SelectQuery("SELECT


* FROM Win32_PerfFormattedData_Counters_ProcessorInformation");
System.Management.ManagementObjectSearcher mos1 = new
System.Management.ManagementObjectSearcher(ms, sq1);
Console.WriteLine("CPU Usage");

foreach (System.Management.ManagementObject m in mos1.Get())


{
Console.WriteLine("PercentProcessorTime: {0}", m["PercentProcessorTime"]);
}
Console.Read();
}
}

You might also like