Register for your free account! | Forgot your password?

You last visited: Today at 07:53

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C# SystemInfo Klasse

Discussion on C# SystemInfo Klasse within the Coding Tutorials forum part of the General Coding category.

Reply
 
Old   #1

 
boxxiebabee's Avatar
 
elite*gold: 0
Join Date: May 2008
Posts: 1,222
Received Thanks: 500
C# SystemInfo Klasse

Moin,

hier ist ne kleine Klasse von mir um ein paar Informationen vom System zu bekommen.

Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Management;
using System.Windows.Forms;
using Microsoft.Win32;

namespace Sors
{
    internal class SystemInfo
    {
        #region User

        //Returns the user name
        public string UserName()
        {
            return Environment.UserName;
        }

        //Returns the user domain name
        public string UserDomain()
        {
            return Environment.UserDomainName;
        }

        #endregion

        #region Operating System

        //Returns the operating system name
        public string OsName()
        {
            var name =
                (from x in
                     new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").Get().OfType<ManagementObject>()
                 select x.GetPropertyValue("Caption")).First();
            return name != null ? name.ToString() : "Unknown";
        }

        //Returns the operating system version
        public string OsVersion()
        {
            return Environment.OSVersion.ToString();
        }

        //Returns the operating system uptime
        public int OsTime()
        {
            return (Environment.TickCount/60);
        }

        #endregion

        #region System

        //Returns the system directory
        public string SystemDirectory()
        {
            return Environment.SystemDirectory;
        }

        //Returns the available ram in megabyte
        public int AvailableRam()
        {
            var pc = new PerformanceCounter("Memory", "Available Bytes");
            return Convert.ToInt32(Math.Round(pc.NextValue()/1048576));
        }

        //Returns all running processes
        public List<string> RunningProcesses()
        {
            Process[] processlist = Process.GetProcesses();
            return processlist.Select(theprocess => theprocess.ProcessName).ToList();
        }

        #endregion

        #region Machine

        //Returns the machine name
        public string MachineName()
        {
            return Environment.MachineName;
        }

        #endregion

        #region Hardware

        //Returns the graphic card name
        public string GraphicCardName()
        {
            var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DisplayConfiguration");
            return (from ManagementObject mo in searcher.Get()
                    from property in
                        mo.Properties.Cast<PropertyData>().Where(property => property.Name == "Description")
                    select property.Value.ToString()).FirstOrDefault();
        }

        //Returns the processor name
        public string CpuName()
        {
            RegistryKey processorName =
                Registry.LocalMachine.OpenSubKey(@"Hardware\Description\System\CentralProcessor\0",
                                                 RegistryKeyPermissionCheck.ReadSubTree);
            return processorName != null
                       ? (processorName.GetValue("ProcessorNameString") != null
                              ? processorName.GetValue("ProcessorNameString").ToString()
                              : null)
                       : null;
        }

        //Returns the prozessor frequency in megacycles
        public int CpuFrequency()
        {
            RegistryKey cpuFrequency =
                Registry.LocalMachine.OpenSubKey(@"Hardware\Description\System\CentralProcessor\0",
                                                 RegistryKeyPermissionCheck.ReadSubTree);
            return cpuFrequency != null
                       ? (cpuFrequency.GetValue("~MHz") != null ? (int) cpuFrequency.GetValue("~MHz") : 0)
                       : 0;
        }

        //Returns the total physical ram amount in megabyte
        public int TotalRam()
        {
            var mc = new ManagementClass("Win32_ComputerSystem");
            ManagementObjectCollection moc = mc.GetInstances();
            return (from ManagementObject item in moc
                    select
                        Convert.ToInt32(
                            Math.Round(Convert.ToDouble(item.Properties["TotalPhysicalMemory"].Value)/1048576, 2))).
                FirstOrDefault();
        }

        //Returns the sound card name
        public string SoundCardName()
        {
            var searcher = new ManagementObjectSearcher("Select ProductName from Win32_SoundDevice");
            return (from ManagementObject mo in searcher.Get()
                    from property in
                        mo.Properties.Cast<PropertyData>().Where(property => property.Name == "ProductName")
                    select property.Value.ToString()).FirstOrDefault();
        }

        #endregion

        #region Resolution

        //Returns the screen resolution height
        public int ScreenResolutionHeight()
        {
            return Screen.PrimaryScreen.Bounds.Height;
        }

        //Returns the screen resolution width
        public int ScreenResolutuinWidth()
        {
            return Screen.PrimaryScreen.Bounds.Width;
        }

        #endregion
    }
}
boxxiebabee is offline  
Thanks
2 Users
Reply


Similar Threads Similar Threads
Volkswechsel alte Klasse(Classic)->neue Klasse(Cata)
01/30/2011 - World of Warcraft - 13 Replies
Hi, Ich würde meinen Untoten Magier gerne zu einem Goblin Magier verändern. Ich weis auch, dass Goblins Magier sein können aber ich finde keine 100% sicheren Infos ob man auch Untoter->Goblin changen kann! Kennt sich da einer aus? Außerdem wird ja der Ruf der alten Heimatstadt auf die neue gewechselt, also sollte in meinem Fall doch nur von Unterstadt->Goblinstadt geändert werden oder? Was ist das langsame Goblinreittier(60%) und was das Schnelle(100%) zu dem meine Skelettpferde...
[C++]Funktion einer Klasse in einer anderen Funktion der Klasse verwenden, aber wie?
07/25/2010 - C/C++ - 3 Replies
Mein Problem ist eigentlich recht simpel und die Lösung wahrscheinlich auch. Da ich bisher fast 0 mit Klassen am Hut hatte, wollte ich mich doch mit dem Thema anfreunden und hatte gleich angefangen: int test::Funktion2() { int temp; cin>>temp; return temp; }
Welche Klasse ist die Beste Klasse
07/06/2010 - Metin2 - 6 Replies
Hallo ich habe heute mal angefangen Metin 2 angefangen und wollte fragen welche klasse ist die beste meine Vorstellung Menge Deff Wird Mich freuen auf Antwort
Na Klasse -.-
12/10/2009 - Metin2 Private Server - 5 Replies
Supa ! Gestern habe ich den Teleporter auf deutsch übersetzt ging alles (also mit dem übersetzen in Filezilla ) und beim einloggen als ich den anklicken wollte stand da : " Möchtest du teleportiert werden?" dann klick ich darauf und plötzlich wirds nix mehr kommen Was soll ich tun?



All times are GMT +1. The time now is 07:54.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.