Esempio n. 1
0
        public override ResultWrangler ProcessQuery()
        {
            //Now go through the management objects return from WMI, and add the relevant values to the wrangler.
            //New sublists are created for each management object in the wrangler.
            try
            {
                if (this._processed == true)
                {
                    this._processingwrangler = this._processingwrangler.Clone();
                }
                this.AddWmiPropertiesToWrangler(this._processingwrangler, SystemConnector.GetWmiManagementObjectList(this._namespace, this._wql), this._propertyTemplates);
            }
            catch (ManagementException e)
            {
                throw new TsGuiKnownException("WMI query caused an error:" + Environment.NewLine + this._wql, e.Message);
            }

            this._processed = true;
            if (this.ShouldIgnore(this._processingwrangler.GetString()) == false)
            {
                this._returnwrangler = this._processingwrangler;
            }
            else
            {
                this._returnwrangler = null;
            }

            return(this._returnwrangler);
        }
Esempio n. 2
0
        //get and environmental variable, trying the sccm ts variables first
        public string GetEnvironmentVariableValue(string variablename)
        {
            string s;

            if (!string.IsNullOrEmpty(variablename))
            {
                //try ts env first
                if (this._sccmconnector != null)
                {
                    s = this._sccmconnector.GetVariableValue(variablename);
                    if (!string.IsNullOrEmpty(s))
                    {
                        return(s);
                    }
                }

                //if hasn't returned already, try system env variables
                s = SystemConnector.GetVariableValue(variablename);
                if (!string.IsNullOrEmpty(s))
                {
                    return(s);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
    public Task <MyHardware> GetHardwareAsync()
    {
        if (_mySystem != null)
        {
            return(Task.FromResult(_mySystem));
        }
        var tcs = new TaskCompletionSource <MyHardware>();
        SystemDiscoverer SystemDiscoverer = new SystemDiscoverer();

        SystemDiscoverer.Discovered += (sysInfo) =>
        {
            myConn = new SystemConnector(sysInfo.IPAddress);
            if (myConn != null)
            {
                mySystem = new MyHardware(myConn);
                tcs.TrySetResult(mySystem);
                return(tcs.Task);
            }
            // This indicated that myConn came back null.
            tcs.TrySetResult(null);
            return(tcs.Task);
        };
        // Make SystemDiscoverer run asynchrnously. We will await it so when it completes we will get the desired MyHardware instance.
        SystemDiscoverer.DiscoverAsync();
        return(tcs.Task);
    }
Esempio n. 4
0
 public string GetVariableValueTest(string Variable)
 {
     return(SystemConnector.GetVariableValue(Variable));
 }
Esempio n. 5
0
        private void Evaluate()
        {
            //virtual machine tests
            foreach (ManagementObject m in SystemConnector.GetWmiManagementObjectCollection(this._namespace, "select Model,Manufacturer from Win32_ComputerSystem"))
            {
                string model = (string)m["Model"];
                string maker = (string)m["Manufacturer"];
                if (string.IsNullOrWhiteSpace(model) == false)
                {
                    //vmware
                    if (model.Contains("VMware"))
                    {
                        this.IsVirtualMachine = true;
                        break;
                    }
                    //hyper-v
                    if (model == "Virtual Machine")
                    {
                        this.IsVirtualMachine = true;
                        break;
                    }
                    //virtualbox
                    if (model.Contains("VirtualBox"))
                    {
                        this.IsVirtualMachine = true;
                        break;
                    }
                    //Parallels
                    if (model.Contains("Parallels"))
                    {
                        this.IsVirtualMachine = true;
                        break;
                    }
                }

                if (string.IsNullOrWhiteSpace(maker) == false)
                {
                    //Xen
                    if (maker.Contains("Xen"))
                    {
                        this.IsVirtualMachine = true;
                        break;
                    }
                }
            }

            //chassis type tests
            foreach (ManagementObject m in SystemConnector.GetWmiManagementObjectCollection(this._namespace, "select ChassisTypes from Win32_SystemEnclosure"))
            {
                Int16[] chassistypes = (Int16[])m["ChassisTypes"];

                foreach (Int16 i in chassistypes)
                {
                    switch (i)
                    {
                    case 8:
                    case 9:
                    case 10:
                    case 11:
                    case 12:
                    case 14:
                    case 18:
                    case 21:
                    {
                        this.IsLaptop = true;
                        break;
                    }

                    case 30:
                    {
                        this.IsLaptop = true;
                        this.IsTablet = true;
                        break;
                    }

                    case 31:
                    {
                        this.IsLaptop      = true;
                        this.IsConvertible = true;
                        break;
                    }

                    case 32:
                    {
                        this.IsLaptop     = true;
                        this.IsDetachable = true;
                        break;
                    }

                    case 3:
                    case 4:
                    case 5:
                    case 6:
                    case 7:
                    case 15:
                    case 16:
                    case 24:
                    case 34:
                    case 35:
                    case 36:
                    {
                        this.IsDesktop = true;
                        break;
                    }

                    case 23:
                    case 25:
                    case 28:
                    case 29:
                    {
                        this.IsServer = true;
                        break;
                    }

                    default:
                    { break; }
                    }
                }
            }

            //ip info gather
            foreach (ManagementObject m in SystemConnector.GetWmiManagementObjectCollection(this._namespace, @"Select DefaultIPGateway,IPAddress,IPSubnet,DHCPServer from Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'"))
            {
                string[] ipaddresses = (string[])m["IPAddress"];

                if (ipaddresses != null)
                {
                    foreach (string s in ipaddresses)
                    {
                        if (string.IsNullOrEmpty(s) == false)
                        {
                            if (s.Contains(":"))
                            {
                                this.IPAddresses6 = AppendToStringList(this.IPAddresses6, s);
                            }
                            else
                            {
                                this.IPAddresses4 = AppendToStringList(this.IPAddresses4, s);
                            }
                        }
                    }
                }


                string[] defaultgateways = (string[])m["DefaultIPGateway"];
                if (defaultgateways != null)
                {
                    foreach (string s in defaultgateways)
                    {
                        if (s.Contains(":"))
                        {
                            this.DefaultGateways6 = AppendToStringList(this.DefaultGateways6, s);
                        }
                        else
                        {
                            this.DefaultGateways4 = AppendToStringList(this.DefaultGateways4, s);
                        }
                    }
                }

                string[] netmasks = (string[])m["IPSubnet"];
                if (netmasks != null)
                {
                    foreach (string s in netmasks)
                    {
                        if (s.Contains("."))
                        {
                            this.IPNetMask4 = AppendToStringList(this.IPNetMask4, s);
                        }
                        else
                        {
                            this.IPNetMask6 = AppendToStringList(this.IPNetMask6, s);
                        }
                    }
                }

                string svr = (string)m["DHCPServer"];
                if (string.IsNullOrWhiteSpace(svr) == false)
                {
                    this.DHCPServer = AppendToStringList(this.DHCPServer, svr);
                }
            }
        }