示例#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));
        }
示例#2
0
 public int GetCPUBits()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return((int)context.Source <Win32_Processor>().First().AddressWidth);
     }
     catch { return(1); }
 }
示例#3
0
 public string GetMoboModel()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return(context.Source <Win32_BaseBoard>().First().Product);
     }
     catch { return(string.Empty); }
 }
示例#4
0
 public string GetBIOSVersion()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return(context.Source <Win32_BIOS>().First().SMBIOSBIOSVersion);
     }
     catch { return(string.Empty); }
 }
示例#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); }
 }
示例#6
0
 public string GetSoundcardName()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return(context.Source <Win32_SoundDevice>().First().Name);
     }
     catch { return(string.Empty); }
 }
示例#7
0
 public string GetMoboBrand()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return(context.Source <Win32_BaseBoard>().First().Manufacturer);
     }
     catch { return(string.Empty); }
 }
示例#8
0
文件: Program.cs 项目: Kayomani/FAP
        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);
            }
        }
示例#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);
            }
        }
示例#10
0
 public string GetGPUDescription()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
         {
             return(context.Source <Win32_VideoController>().First().Name);
         }
     }
     catch { return(string.Empty); }
 }
示例#11
0
 public int GetGPUCount()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
         {
             return(context.Source <Win32_VideoController>().Count());
         }
     }
     catch { return(1); }
 }
示例#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));
            }
        }
示例#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); }
 }
示例#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); }
 }
示例#15
0
 public int GetCPUCores()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
         {
             return (int)context.Source<Win32_Processor>().First().NumberOfCores;
         }
     }
     catch
     {
         return 1;
     }
 }
示例#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);
            }
        }
示例#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));
            }
        }
示例#18
0
文件: Program.cs 项目: Kayomani/FAP
        /// <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));
            }
        }
示例#19
0
文件: Program.cs 项目: Kayomani/FAP
        /// <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);
            }
        }
示例#20
0
 public int GetCPUThreads()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
         {
             return((int)context.Source <Win32_Processor>().First().NumberOfLogicalProcessors);
         }
     }
     catch
     {
         return(1);
     }
 }
示例#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); }
 }
示例#22
0
文件: Program.cs 项目: Kayomani/FAP
        /// <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));
        }
示例#23
0
 public string GetGPUDescription()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
         {
             return context.Source<Win32_VideoController>().First().Name;
         }
     }
     catch { return string.Empty; }
 }
示例#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);
            }
        }
示例#25
0
 public string GetMoboModel()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return context.Source<Win32_BaseBoard>().First().Product;
     }
     catch { return string.Empty; }
 }
示例#26
0
 public int GetGPUCount()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
         {
             return context.Source<Win32_VideoController>().Count();
         }
     }
     catch { return 1; }
 }
示例#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; }
 }
示例#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; }
 }
示例#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; }
 }
示例#30
0
 public string GetSoundcardName()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return context.Source<Win32_SoundDevice>().First().Name;
     }
     catch { return string.Empty; }
 }
示例#31
0
 public string GetMoboBrand()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return context.Source<Win32_BaseBoard>().First().Manufacturer;
     }
     catch { return string.Empty; }
 }
示例#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; }
 }
示例#33
0
 public string GetBIOSVersion()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return context.Source<Win32_BIOS>().First().SMBIOSBIOSVersion;
     }
     catch { return string.Empty; }
 }
示例#34
0
文件: Program.cs 项目: Kayomani/FAP
        /// <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));
            }
        }
示例#35
0
 public int GetCPUBits()
 {
     try
     {
         using (WmiContext context = new WmiContext(@"\\localhost"))
             return (int)context.Source<Win32_Processor>().First().AddressWidth;
     }
     catch { return 1; }
 }
示例#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);
            }
        }