示例#1
0
        public override ResponseBase ExecuteRequest()
        {
            var pf = new PerfmonDataResponse();

            pf.CPUuse  = Int32.Parse(WmiQuery.GetWMIdata("Win32_PerfFormattedData_PerfOS_Processor", "PercentProcessorTime", "Name", "_Total"));
            pf.RAMfree = Int32.Parse(WmiQuery.GetWMIdata("Win32_PerfFormattedData_PerfOS_Memory", "AvailableMBytes"));
            string[] properties = new string[] { "FreeMegabytes", "AvgDiskQueueLength" };
            var      values     = WmiQuery.GetWMIdata("Win32_PerfFormattedData_PerfDisk_LogicalDisk", properties, "Name", "C:");

            pf.DiskFree  = Int32.Parse(values["FreeMegabytes"]);
            pf.DiskQueue = Int32.Parse(values["AvgDiskQueueLength"]);

            #region Workaround for showing the graph in UI
            if (!realDiskFreeValue.HasValue)
            {
                pf.DiskFree      -= 1;
                realDiskFreeValue = pf.DiskFree;
            }
            if (!realDiskQueueValue.HasValue)
            {
                pf.DiskQueue      += 1;
                realDiskQueueValue = pf.DiskQueue;
            }
            #endregion

            return(pf);
        }
示例#2
0
        public void ServerManager_WmiQuery()
        {
            ServiceManager sm;
            WmiResultSet   wmiResults;

            WmiQuery[] wmiQueries;

            sm = new ServiceManager(router);
            sm.Connect(ServiceManager.AbstractEP);

            try
            {
                wmiResults = new WmiResultSet();
                wmiResults.Add(new WmiResult("query1", new ManagementObjectSearcher("select * from CIM_LogicalDisk")));
                wmiResults.Add(new WmiResult("query2", new ManagementObjectSearcher("select * from CIM_Memory")));

                wmiQueries = new WmiQuery[] {
                    new WmiQuery("query1", "select * from CIM_LogicalDisk"),
                    new WmiQuery("query2", "select * from CIM_Memory")
                };

                Assert.AreEqual(wmiResults, sm.WmiQuery(wmiQueries));
            }
            finally
            {
                sm.Disconnect();
            }
        }
        public override ResponseBase ExecuteRequest()
        {
            var id = new IdentificationDataResponse
            {
                DeviceName   = Environment.MachineName,
                SerialNumber = WmiQuery.GetWMIdata("Win32_BaseBoard", "SerialNumber")
            };

            return(id);
        }
示例#4
0
        public void AddWmiPropertiesToWrangler_Test(WmiQueryTestArgs TestArgs)
        {
            //protected void AddWmiPropertiesToWrangler(ResultWrangler Wrangler, IEnumerable<ManagementObject> WmiObjectList, List<KeyValuePair<string, XElement>> PropertyTemplates)
            WmiQuery      query = new WmiQuery(new DummyLinkTarget());
            PrivateObject obj   = new PrivateObject(query);

            object[] args = new object[3] {
                TestArgs.Wrangler, TestArgs.ManagementObjectList, TestArgs.PropertyTemplates
            };
            obj.Invoke("AddWmiPropertiesToWrangler", args);

            ResultWrangler wrangler = TestArgs.Wrangler;
            string         s        = wrangler.GetString();

            NUnit.Framework.Assert.AreEqual(s, TestArgs.ExpectedResult);
        }
示例#5
0
        public override ResponseBase ExecuteRequest()
        {
            OsInfoResponse os = new OsInfoResponse();

            //retrieve all data in one call because WMI call usually takes some time...
            string[] properties = new string[] { "Caption", "Version", "OSArchitecture", "TotalVisibleMemorySize", "FreePhysicalMemory", "SystemDrive" };
            Dictionary <string, string> values = WmiQuery.GetWMIdata("Win32_OperatingSystem", properties);

            os.OsName    = values["Caption"];
            os.OsVersion = values["Version"];
            if (values.ContainsKey("OSArchitecture"))
            {
                os.OsArchitecture = values["OSArchitecture"];
            }
            else
            {
                os.OsArchitecture = "32 bit";                                                                                                             //old 32-bit systems has no OSArchitecture property
            }
            os.RamSize         = Int32.Parse(values["TotalVisibleMemorySize"]) / 1024;                                                                    //in Mb
            os.SystemDrive     = values["SystemDrive"];
            os.SystemDriveSize = (int)(Double.Parse(WmiQuery.GetWMIdata("Win32_LogicalDisk", "Size", "Caption", os.SystemDrive)) / (1024 * 1024 * 1024)); //Gb

            return(os);
        }
 Watcher = new ManagementEventWatcher(Scope, new EventQuery(WmiQuery));
示例#7
0
        static void Test()
        {
            try
            {
                using (var Wmi = new WmiQuery())
                {
                    if (Wmi.IsConnected == true)
                    {
                        //// UUID
                        //var computer = Wmi.GetUUID();
                        //Console.WriteLine(computer.Id);

                        //// Profile Paths
                        //foreach (string s in Wmi.GetUserProfilePaths())
                        //{
                        //    Console.WriteLine(s);
                        //}

                        //// .NET Frameworks
                        //foreach (string s in Wmi.GetNetFramework())
                        //{
                        //    Console.WriteLine(s);
                        //}

                        //// Processors
                        //foreach (IProcessorProvider p in Wmi.GetProcessors())
                        //{
                        //    Console.WriteLine($"Name {p.Name}, Load Percent: {p.LoadPercentage}");
                        //}

                        //// Bios
                        //foreach (IBiosProvider b in Wmi.GetBios())
                        //{
                        //    Console.WriteLine($"Manufacturer: {b.Manufacturer}, Serial: {b.SerialNumber}, Version: {b.SMBIOSBIOSVersion}");
                        //}

                        //// Check if it's a portable device
                        //var portable = Wmi.IsPortableDevice();
                        //Console.WriteLine(portable);

                        //// Server Sessions
                        //foreach (IServerSessionProvider c in Wmi.GetServerSessions())
                        //{
                        //    Console.WriteLine($"Username: {c.UserName}, Computer: {c.ComputerName}");
                        //}

                        //// Operating system
                        //foreach (IOperatingSystemProvider c in Wmi.GetOperatingSystem())
                        //{
                        //    Console.WriteLine($"Caption: {c.Caption}, csname: {c.csname}, FreePhysicalMemory: {c.FreePhysicalMemory}, FreePhysicalMemoryFormatted: {c.FreePhysicalMemoryFormatted}, InstallDate: {c.InstallDate}, IsServer: {c.IsServer}, " +
                        //        $"LastBootUpTime: {c.LastBootUpTime}, Name: {c.Name}, OSArchitecture: {c.OSArchitecture}, ServicePackMajorVersion: {c.ServicePackMajorVersion}, " +
                        //        $"SystemDrive: {c.SystemDrive}, Version: {c.Version}, WindowsDirectory: {c.WindowsDirectory}");
                        //}

                        //// Kill a process
                        //Wmi.EndProcess("notepad.exe", "rkuet");

                        //// Process List
                        //foreach (IProcessProvider c in Wmi.GetProcessList())
                        //{
                        //    Console.WriteLine($"Caption: {c.Caption}, CommandLine: {c.CommandLine}, ParentProcessID: {c.ParentProcessID}, ProcessID: {c.ProcessID}, ThreadCount: {c.ThreadCount}, WorkingSetSize: {c.WorkingSetSize}, " +
                        //        $"WorkingSetSizeFormatted: {c.WorkingSetSizeFormatted}");
                        //}

                        //// Get a service controller
                        //ServiceController s = Wmi.GetServiceController("BDESVC", "127.0.0.1");
                        //Console.WriteLine(s.DisplayName);

                        //// Get a list of all services
                        //foreach (Acceledesk.Wmi.IServiceProvider c in Wmi.GetServices())
                        //{
                        //    Console.WriteLine($"Caption: {c.Caption}, Description: {c.Description}, PathName: {c.PathName}, ServiceType: {c.ServiceType}, StartMode: {c.StartMode}, State: {c.State}");
                        //}

                        //// Get the network adapter
                        //foreach (INetworkAdapterConfigurationProvider c in Wmi.GetNetAdapter())
                        //{
                        //    Console.WriteLine($"Description: {c.Description}, MACAddress: {c.MACAddress}, DNSDomain: {c.DNSDomain}, DHCPServer: {c.DHCPServer}, DHCPLeaseObtained: {c.DHCPLeaseObtained}, DHCPEnabled: {c.DHCPEnabled}");

                        //    Console.WriteLine(); Console.WriteLine("IP Addresses");
                        //    foreach (string ip in c.IPAddress)
                        //    {
                        //        Console.WriteLine(ip);
                        //    }

                        //    Console.WriteLine(); Console.WriteLine("IPSubnet");
                        //    foreach (string ip in c.IPSubnet)
                        //    {
                        //        Console.WriteLine(ip);
                        //    }

                        //    Console.WriteLine(); Console.WriteLine("DefaultGateway");
                        //    if (c.DefaultGateway != null)
                        //    {
                        //        foreach (string ip in c.DefaultGateway)
                        //        {
                        //            Console.WriteLine(ip);
                        //        }
                        //    }
                        //}

                        //// Get Shares
                        //foreach (IShareProvider c in Wmi.GetShares())
                        //{
                        //    Console.WriteLine($"Name: {c.Name}, Description: {c.Description}, Path: {c.Path}");
                        //}

                        //// Get the Logical Drive
                        //foreach (ILogicalDiskProvider c in Wmi.GetLogicalDisk())
                        //{
                        //    Console.WriteLine($"Name: {c.Name}, Description: {c.Description}, Path: {c.Path}, Size: {c.Size}, SizeFormatted: {c.SizeFormatted}, Usage: {c.Usage}, UsageFormatted: {c.UsageFormatted}, VolumeName: {c.VolumeName}, VolumeSerialNumber: {c.VolumeSerialNumber}, Filesystem: {c.Filesystem}");
                        //}

                        //// Get the Disk Drive
                        //foreach (IDiskDriveProvider c in Wmi.GetDiskDrive())
                        //{
                        //    Console.WriteLine($"InterfaceType: {c.InterfaceType}, MediaType: {c.MediaType}, Model: {c.Model}, Partitions: {c.Partitions}, SerialNumber: {c.SerialNumber}, Signature: {c.Signature}, Size: {c.Size}, SizeFormatted: {c.SizeFormatted}");
                        //}

                        //// Get the Display
                        //foreach (IDisplayConfigurationProvider c in Wmi.GetDisplay())
                        //{
                        //    Console.WriteLine($"BitsPerPel: {c.BitsPerPel}, DeviceName: {c.DeviceName}, DriverVersion: {c.DriverVersion}");
                        //}

                        //// Get Printers
                        //foreach (IPrinterProvider c in Wmi.GetPrinters())
                        //{
                        //    Console.WriteLine($"Caption: {c.Caption}, Default: {c.Default}, DriverName: {c.DriverName}, Local: {c.Local}, PortName: {c.PortName}, Queued: {c.Queued}, Shared: {c.Shared}, ShareName: {c.ShareName}, Status: {c.Status}, StatusInfo: {c.StatusInfo}");
                        //}

                        // Get Computer
                        //foreach (IComputerSystemProvider c in Wmi.GetComputer())
                        //{
                        //    Console.WriteLine($"Name: {c.Name}, Domain: {c.Domain}, Manufacturer: {c.Manufacturer}, Model: {c.Model}, PartOfDomain: {c.PartOfDomain}, SystemType: {c.SystemType}, TotalPhysicalMemory: {c.TotalPhysicalMemory}, TotalPhysicalMemoryFormatted: {c.TotalPhysicalMemoryFormatted}, UserName: {c.UserName}, UserNameFormatted: {c.UserNameFormatted}");
                        //}

                        // Get Environment Variables
                        Console.WriteLine(Wmi.GetEnvironmentVariables());
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }