/// <summary> /// Queries the available system memory /// </summary> /// <param name="context"></param> private static void QueryAvailableMemory(WmiContext context) { var query = from memory in context.Source <Win32_PerfFormattedData_PerfOS_Memory>() select memory; Console.WriteLine(String.Format("Available memory: {0}MB.", query.Single().AvailableMBytes)); ulong availMemory = (from computerSystem in context.Source <Win32_ComputerSystem>() select computerSystem.TotalPhysicalMemory / 1048576).Single(); Console.WriteLine(String.Format("Available memory: {0}MB.", availMemory)); }
public int GetCPUBits() { try { using (WmiContext context = new WmiContext(@"\\localhost")) return((int)context.Source <Win32_Processor>().First().AddressWidth); } catch { return(1); } }
public string GetMoboModel() { try { using (WmiContext context = new WmiContext(@"\\localhost")) return(context.Source <Win32_BaseBoard>().First().Product); } catch { return(string.Empty); } }
public string GetBIOSVersion() { try { using (WmiContext context = new WmiContext(@"\\localhost")) return(context.Source <Win32_BIOS>().First().SMBIOSBIOSVersion); } catch { return(string.Empty); } }
public int GetHDDCount() { try { using (WmiContext context = new WmiContext(@"\\localhost")) return(context.Source <Win32_LogicalDisk>().Where(d => d.DriveType == 3).Count()); } catch { return(0); } }
public string GetSoundcardName() { try { using (WmiContext context = new WmiContext(@"\\localhost")) return(context.Source <Win32_SoundDevice>().First().Name); } catch { return(string.Empty); } }
public string GetMoboBrand() { try { using (WmiContext context = new WmiContext(@"\\localhost")) return(context.Source <Win32_BaseBoard>().First().Manufacturer); } catch { return(string.Empty); } }
private static void QueryAccounts(WmiContext context) { var query = from account in context.Source<Win32_UserAccount>() select account; foreach (Win32_UserAccount account in query) { Console.WriteLine(account.Name); } }
private static void QueryAccounts(WmiContext context) { var query = from account in context.Source <Win32_UserAccount>() select account; foreach (Win32_UserAccount account in query) { Console.WriteLine(account.Name); } }
public string GetGPUDescription() { try { using (WmiContext context = new WmiContext(@"\\localhost")) { return(context.Source <Win32_VideoController>().First().Name); } } catch { return(string.Empty); } }
public int GetGPUCount() { try { using (WmiContext context = new WmiContext(@"\\localhost")) { return(context.Source <Win32_VideoController>().Count()); } } catch { return(1); } }
/// <summary> /// Example of querying CPUs /// </summary> /// <param name="context">The WMI query context</param> private static void QueryProcessors(WmiContext context) { var query = from processor in context.Source <Win32_Processor>() select processor; foreach (Win32_Processor processor in query) { Console.WriteLine(String.Format("DeviceID: {0}", processor.DeviceID)); Console.WriteLine(String.Format("Usage: {0}%", processor.LoadPercentage)); } }
public long GetTotalGPUMemory() { try { using (WmiContext context = new WmiContext(@"\\localhost")) { var totals = from card in context.Source <Win32_VideoController>() select(long) card.AdapterRAM; return(totals.Sum()); } } catch { return(1); } }
public long GetMemorySize() { try { using (WmiContext context = new WmiContext(@"\\localhost")) { var totals = from stick in context.Source <Win32_PhysicalMemory>() select(long) stick.Capacity; return(totals.Sum()); } } catch { return(0); } }
public int GetCPUCores() { try { using (WmiContext context = new WmiContext(@"\\localhost")) { return (int)context.Source<Win32_Processor>().First().NumberOfCores; } } catch { return 1; } }
/// <summary> /// Example of querying the eventlog 'Application' and take 5 /// </summary> /// <param name="context"></param> public static void QueryEvents(WmiContext context) { //NOTE: We havent overloaded 'Take' so it deferres to the not optimized IEnumerable<T> of Take var query = (from evt in context.Source <Win32_NTLogEvent>() where evt.Logfile == "Application" && evt.Message.Contains(".exe") select evt).Take(5); foreach (Win32_NTLogEvent evt in query) { Console.WriteLine(evt.TimeWritten); Console.WriteLine(evt.Message); } }
/// <summary> /// Example of querying system drives /// Query drives that do not have an X in their name, and more that 1024 bytes of space /// </summary> public static void QueryDrives(WmiContext context) { var query = from drive in context.Source <Win32_LogicalDisk>() where drive.DriveType == 3 || drive.DriveType == 4 select drive; foreach (Win32_LogicalDisk drive in query) { Console.WriteLine(String.Format("Drive {0} has {1}MB free. Total size: {2}MB.", drive.DeviceID, drive.FreeSpace / 106496, drive.Size / 106496, drive.DriveType)); } }
/// <summary> /// Example of querying system drives /// Query drives that do not have an X in their name, and more that 1024 bytes of space /// </summary> public static void QueryDrives(WmiContext context) { var query = from drive in context.Source<Win32_LogicalDisk>() where drive.DriveType == 3 || drive.DriveType == 4 select drive; foreach (Win32_LogicalDisk drive in query) { Console.WriteLine(String.Format("Drive {0} has {1}MB free. Total size: {2}MB.", drive.DeviceID, drive.FreeSpace / 106496, drive.Size / 106496, drive.DriveType)); } }
/// <summary> /// Example of querying the eventlog 'Application' and take 5 /// </summary> /// <param name="context"></param> public static void QueryEvents(WmiContext context) { //NOTE: We havent overloaded 'Take' so it deferres to the not optimized IEnumerable<T> of Take var query = (from evt in context.Source<Win32_NTLogEvent>() where evt.Logfile == "Application" && evt.Message.Contains(".exe") select evt).Take(5); foreach (Win32_NTLogEvent evt in query) { Console.WriteLine(evt.TimeWritten); Console.WriteLine(evt.Message); } }
public int GetCPUThreads() { try { using (WmiContext context = new WmiContext(@"\\localhost")) { return((int)context.Source <Win32_Processor>().First().NumberOfLogicalProcessors); } } catch { return(1); } }
public long GetTotalHDDFree() { try { using (WmiContext context = new WmiContext(@"\\localhost")) { var totals = from disk in context.Source <Win32_LogicalDisk>() where disk.DriveType == 3 select(long) disk.FreeSpace; return(totals.Sum()); } } catch { return(0); } }
/// <summary> /// Queries the available system memory /// </summary> /// <param name="context"></param> private static void QueryAvailableMemory(WmiContext context) { var query = from memory in context.Source<Win32_PerfFormattedData_PerfOS_Memory>() select memory; Console.WriteLine(String.Format("Available memory: {0}MB.", query.Single().AvailableMBytes)); ulong availMemory = (from computerSystem in context.Source<Win32_ComputerSystem>() select computerSystem.TotalPhysicalMemory / 1048576).Single(); Console.WriteLine(String.Format("Available memory: {0}MB.", availMemory)); }
public string GetGPUDescription() { try { using (WmiContext context = new WmiContext(@"\\localhost")) { return context.Source<Win32_VideoController>().First().Name; } } catch { return string.Empty; } }
private static void QueryProcesses(WmiContext context) { var query = from process in context.Source<Win32_Process>() select process; foreach (Win32_Process process in query) { Console.WriteLine(process.CommandLine); } }
public string GetMoboModel() { try { using (WmiContext context = new WmiContext(@"\\localhost")) return context.Source<Win32_BaseBoard>().First().Product; } catch { return string.Empty; } }
public int GetGPUCount() { try { using (WmiContext context = new WmiContext(@"\\localhost")) { return context.Source<Win32_VideoController>().Count(); } } catch { return 1; } }
public long GetTotalGPUMemory() { try { using (WmiContext context = new WmiContext(@"\\localhost")) { var totals = from card in context.Source<Win32_VideoController>() select (long)card.AdapterRAM; return totals.Sum(); } } catch { return 1; } }
public long GetTotalHDDFree() { try { using (WmiContext context = new WmiContext(@"\\localhost")) { var totals = from disk in context.Source<Win32_LogicalDisk>() where disk.DriveType == 3 select (long)disk.FreeSpace; return totals.Sum(); } } catch { return 0; } }
public int GetHDDCount() { try { using (WmiContext context = new WmiContext(@"\\localhost")) return context.Source<Win32_LogicalDisk>().Where(d => d.DriveType == 3).Count(); } catch { return 0; } }
public string GetSoundcardName() { try { using (WmiContext context = new WmiContext(@"\\localhost")) return context.Source<Win32_SoundDevice>().First().Name; } catch { return string.Empty; } }
public string GetMoboBrand() { try { using (WmiContext context = new WmiContext(@"\\localhost")) return context.Source<Win32_BaseBoard>().First().Manufacturer; } catch { return string.Empty; } }
public long GetMemorySize() { try { using (WmiContext context = new WmiContext(@"\\localhost")) { var totals = from stick in context.Source<Win32_PhysicalMemory>() select (long)stick.Capacity; return totals.Sum(); } } catch { return 0; } }
public string GetBIOSVersion() { try { using (WmiContext context = new WmiContext(@"\\localhost")) return context.Source<Win32_BIOS>().First().SMBIOSBIOSVersion; } catch { return string.Empty; } }
/// <summary> /// Example of querying CPUs /// </summary> /// <param name="context">The WMI query context</param> private static void QueryProcessors(WmiContext context) { var query = from processor in context.Source<Win32_Processor>() select processor; foreach (Win32_Processor processor in query) { Console.WriteLine(String.Format("DeviceID: {0}", processor.DeviceID)); Console.WriteLine(String.Format("Usage: {0}%", processor.LoadPercentage)); } }
public int GetCPUBits() { try { using (WmiContext context = new WmiContext(@"\\localhost")) return (int)context.Source<Win32_Processor>().First().AddressWidth; } catch { return 1; } }
/* * "Win32_Process","ProcessId,CommandLine", "Win32_PerfFormattedData_PerfProc_Process","IDProcess,Name,PercentProcessorTime", */ private static void Test(WmiContext context) { List<string> entires = new List<string>(); var query = from process in context.Source<Win32_Process>() join perf in context.Source<Win32_PerfFormattedData_PerfProc_Process>() on process.ProcessId equals perf.IDProcess where process.CommandLine != null && process.CommandLine.Trim().EndsWith("weblogic.Server") select String.Format("{0}:{1}", GetServerName(process.CommandLine), perf.PercentProcessorTime); foreach (var s in query) { Console.WriteLine(s); } }