Jump to content

Meta

Members
  • Posts

    3
  • Joined

  • Last visited

Posts posted by Meta

  1. Hi Paul,

     

    Thank you for a quick respons. I can try it on my home system. Right now im att work and im sitting on Win 8.1. Is it possible that it can differ between win 7 and win 8.1? Also witch .NET framework version are u uising? Can that be the problem? Because when i compile the code i seent you it works then when i run the .dll fil in pc monitor the when i look under my plugin its just trying to load the data then after a while it says no data available. But when i comet away the red marked code and run it again then it works. I get the indo i want.

     

    Best Regards,

    Meta 

  2. Hi Paul,

     

    I have a question regarding your code for the project PaulCsiki.SystemInfoPlugin. I have modify it a little bit to extarct som more information about my system but im stuck now. The question i have is why som of the data wont show in my plugin. If you take a look down here in the code, the blue marked code works just fine but the red does not?  Why? What did I do wrong? It seams as none of the Win32_PerfRawData classes wont work when I try to SELECT data from them. Can you please help me?

     

    namespace Test3
    {
        public class Plugin : ClientPlugin
        {
            private bool Paged
            {
                get { return GetValueForKey("paged") == "true"; }
                set { SetValueForKey("paged", value ? "true" : "false"); }
            }
     
            public override Groups GetAdditionalComputerDetails()
            {
                return GetData(Paged);
            }
     
            public override void CommandReceived(int commandId)
            {
                Paged = !Paged;
            }
     
            public override Groups GetPageDetails(int pageId)
            {
                return GetData(false);
            }
     
            public override void PageCommandReceived(int pageId, int commandId)
            {
                CommandReceived(commandId);
            }
     
            private Groups GetData(bool paged)
            {
                var container = new Groups();
     
                if (paged)
                {
                    var page = new Group("SystemInfo Plugin");
                    page.Items.Add(new PageItem(1, "Open SystemInfo"));
                    page.Items.Add(new CommandItem(1, Paged ? "Disable paged view" : "Enable paged view"));
                    container.Add(page);
                }
                else
                {
                    var wmiPath = string.Format(@"\\{0}\root\cimv2", Environment.MachineName);
                    
                    var biosDetails = QueryWMI(wmiPath, "SELECT Version FROM Win32_BIOS");
                    var osDetails = QueryWMI(wmiPath, "SELECT Caption, " +
                                                      "Version, " +
                                                      "WindowsDirectory, " + 
                                                      "FreePhysicalMemory, " +
                                                      "TotalVirtualMemorySize, " +
                                                      "FreeVirtualMemory, " +
                                                      "SizeStoredInPagingFiles FROM Win32_OperatingSystem");
                    var computerDetails = QueryWMI(wmiPath, "SELECT Name, " +
                                                            "Manufacturer, " +
                                                            "Model, " +
                                                            "UserName, " +
                                                            "TotalPhysicalMemory FROM Win32_ComputerSystem");
                    var processorDetails = QueryWMI(wmiPath, "SELECT Description, " +
                                                             "LoadPercentage, " +
                                                             "NumberOfCores FROM Win32_Processor");
                    var memoryDetails = QueryWMI(wmiPath, "SELECT AvailableMBytes, " +
                                                                "Description, " +
                                                                "CacheBytes FROM Win32_PerfRawData_PerfOS_Memory");
                    var networkDetails = QueryWMI(wmiPath, "SELECT Name, " +
                                                             "UserName, " +
                                                             "ConnectionState, " +
                                                             "RemoteName, " +
                                                             "RemotePath, " +
                                                             "Status FROM Win32_NetworkConnection");
                    var tcpipDetails = QueryWMI(wmiPath, "SELECT Name, " +
                                                             "Description, " +
                                                             "Caption, " +
                                                             "BytesSentPerSec, " +
                                                             "BytesReceivedPerSec, " +
                                                             "BytesTotalPerSec, " +
                                                             "CurrentBandwidth, " +
                                                             "PacketsPerSec FROM Win32_PerfRawData_Tcpip_NetworkInterface");
     
                    if (biosDetails != null)
                    {
                        var biosGroup = new Group("BIOS Details");
                        foreach (var biosDetail in biosDetails)
                            biosGroup.Items.Add(new SimpleItem(biosDetail.Name, biosDetail.Value.ToString()));
                        container.Add(biosGroup);
                    }
                    if (osDetails != null)
                    {
                        var osGroup = new Group("Operating System Details");
                        foreach (var osDetail in osDetails)
                            osGroup.Items.Add(new SimpleItem(osDetail.Name, osDetail.Value.ToString()));
                        container.Add(osGroup);
                    }
                    if (computerDetails != null)
                    {
                        var computerGroup = new Group("Computer Details");
                        foreach (var computerDetail in computerDetails)
                            computerGroup.Items.Add(new SimpleItem(computerDetail.Name, computerDetail.Value.ToString()));
                        container.Add(computerGroup);
                    }
                    if (processorDetails != null)
                    {
                        var processorGroup = new Group("Processor Details");
                        foreach (var processorDetail in processorDetails)
                            processorGroup.Items.Add(new SimpleItem(processorDetail.Name, processorDetail.Value.ToString()));
                        container.Add(processorGroup);
                    }
                    if (memoryDetails != null)
                    {
                        var memoryGroup = new Group("Memory Details");
                        foreach (var memoryDetail in memoryDetails)
                            memoryGroup.Items.Add(new SimpleItem(memoryDetail.Name, memoryDetail.Value.ToString()));
                        container.Add(memoryGroup);
                    }
                    if (networkDetails != null)
                    {
                        var networkGroup = new Group("Network Details");
                        foreach (var networkDetail in networkDetails)
                            networkGroup.Items.Add(new SimpleItem(networkDetail.Name, networkDetail.Value.ToString()));
                        container.Add(networkGroup);
                    } 
                    if (tcpipDetails != null)
                    {
                        var tcpipGroup = new Group("TCPIP Details");
                        foreach (var tcpipDetail in tcpipDetails)
                            tcpipGroup.Items.Add(new SimpleItem(tcpipDetail.Name, tcpipDetail.Value.ToString()));
                        container.Add(tcpipGroup);
                    }
     
                    if (container.Count == 0)
                    {
                        var error = new Group("Error");
                        error.Items.Add(new SimpleItem("Error", "No settings founds, check your queries.", SimpleItemStyle.ERROR));
                        container.Add(error);
                    }
     
                    var commands = new Group("Commands");
                    commands.Items.Add(new CommandItem(1, Paged ? "Disable paged view" : "Enable paged view"));
                    container.Add(commands);
                }
     
                return container;
            }
     
            public override Version GetMinimumRequiredAgentVersion()
            {
                return new Version(3, 8);
            }
     
            public override string GetPluginName()
            {
                return "META.SystemInfoPlugin";
            }
     
            public override string GetPluginDescription()
            {
                return "Plugin that shows information of your system using WMI";
            }
     
            public override Version GetPluginVersion()
            {
                return new Version(1, 0);
            }
     
            private static IEnumerable<PropertyData> QueryWMI(string path, string query)
            {
                ManagementObjectCollection coll = null;
                ManagementObjectSearcher searcher = null;
                var list = new List<PropertyData>();
                try
                {
                    searcher = new ManagementObjectSearcher(path, query);
                    coll = searcher.Get();
                    list.AddRange(coll.OfType<ManagementObject>().Select(item => item.Properties).SelectMany(innerItem => innerItem.OfType<PropertyData>()));
                    return list;
                }
                catch
                {
                    return list;
                }
                finally
                {
                    if (coll != null)
                        coll.Dispose();
                    if (searcher != null)
                        searcher.Dispose();
                }
            }
        }
    }
     
×
×
  • Create New...