Esempio n. 1
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));
        }
Esempio n. 2
0
 public int GetCPUBits()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return((int)context.Source <Win32_Processor>().First().AddressWidth);
     }
     catch { return(1); }
 }
Esempio n. 3
0
 public string GetMoboModel()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return(context.Source <Win32_BaseBoard>().First().Product);
     }
     catch { return(string.Empty); }
 }
Esempio n. 4
0
 public string GetBIOSVersion()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return(context.Source <Win32_BIOS>().First().SMBIOSBIOSVersion);
     }
     catch { return(string.Empty); }
 }
Esempio n. 5
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); }
 }
Esempio n. 6
0
 public string GetSoundcardName()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return(context.Source <Win32_SoundDevice>().First().Name);
     }
     catch { return(string.Empty); }
 }
Esempio n. 7
0
 public string GetMoboBrand()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return(context.Source <Win32_BaseBoard>().First().Manufacturer);
     }
     catch { return(string.Empty); }
 }
Esempio n. 8
0
        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);
            }
        }
Esempio n. 9
0
        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);
            }
        }
Esempio n. 10
0
 public string GetGPUDescription()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
         {
             return(context.Source <Win32_VideoController>().First().Name);
         }
     }
     catch { return(string.Empty); }
 }
Esempio n. 11
0
 public int GetGPUCount()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
         {
             return(context.Source <Win32_VideoController>().Count());
         }
     }
     catch { return(1); }
 }
Esempio n. 12
0
        /// <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));
            }
        }
Esempio n. 13
0
 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); }
 }
Esempio n. 14
0
 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); }
 }
Esempio n. 15
0
 public int GetCPUCores()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
         {
             return (int)context.Source<Win32_Processor>().First().NumberOfCores;
         }
     }
     catch
     {
         return 1;
     }
 }
Esempio n. 16
0
        /// <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);
            }
        }
Esempio n. 17
0
        /// <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));
            }
        }
Esempio n. 18
0
        /// <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));
            }
        }
Esempio n. 19
0
        /// <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);
            }
        }
Esempio n. 20
0
 public int GetCPUThreads()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
         {
             return((int)context.Source <Win32_Processor>().First().NumberOfLogicalProcessors);
         }
     }
     catch
     {
         return(1);
     }
 }
Esempio n. 21
0
 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); }
 }
Esempio n. 22
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));
        }
Esempio n. 23
0
 public string GetGPUDescription()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
         {
             return context.Source<Win32_VideoController>().First().Name;
         }
     }
     catch { return string.Empty; }
 }
Esempio n. 24
0
        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);
            }
        }
Esempio n. 25
0
 public string GetMoboModel()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return context.Source<Win32_BaseBoard>().First().Product;
     }
     catch { return string.Empty; }
 }
Esempio n. 26
0
 public int GetGPUCount()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
         {
             return context.Source<Win32_VideoController>().Count();
         }
     }
     catch { return 1; }
 }
Esempio n. 27
0
 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; }
 }
Esempio n. 28
0
 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; }
 }
Esempio n. 29
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; }
 }
Esempio n. 30
0
 public string GetSoundcardName()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return context.Source<Win32_SoundDevice>().First().Name;
     }
     catch { return string.Empty; }
 }
Esempio n. 31
0
 public string GetMoboBrand()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return context.Source<Win32_BaseBoard>().First().Manufacturer;
     }
     catch { return string.Empty; }
 }
Esempio n. 32
0
 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; }
 }
Esempio n. 33
0
 public string GetBIOSVersion()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return context.Source<Win32_BIOS>().First().SMBIOSBIOSVersion;
     }
     catch { return string.Empty; }
 }
Esempio n. 34
0
        /// <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));
            }
        }
Esempio n. 35
0
 public int GetCPUBits()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return (int)context.Source<Win32_Processor>().First().AddressWidth;
     }
     catch { return 1; }
 }
Esempio n. 36
0
        /*
         *
           "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);
            }
        }