コード例 #1
0
ファイル: GClass11.cs プロジェクト: StartZYP/XratVirus
    // Token: 0x0600006F RID: 111 RVA: 0x000058E0 File Offset: 0x00003AE0
    public static int smethod_3()
    {
        int result;

        try
        {
            int    num         = 0;
            string queryString = "Select * From Win32_ComputerSystem";
            using (ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(queryString))
            {
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        double           num2             = Convert.ToDouble(managementObject["TotalPhysicalMemory"]);
                        num = (int)(num2 / 1048576.0);
                    }
                }
            }
            result = num;
        }
        catch
        {
            result = -1;
        }
        return(result);
    }
コード例 #2
0
        public static void RenamePrinter(string _ptr_device, string newName)
        {
            oManagementScope = new ManagementScope(ManagementPath.DefaultPath);
            oManagementScope.Connect();
            SelectQuery selectQuery = new SelectQuery();

            selectQuery.QueryString = "SELECT * FROM Win32_Printer WHERE Name = '" + _ptr_device.Replace("\\", "\\\\") + "'";
            ManagementObjectSearcher   managementObjectSearcher   = new ManagementObjectSearcher(oManagementScope, selectQuery);
            ManagementObjectCollection managementObjectCollection = managementObjectSearcher.Get();

            if (managementObjectCollection.Count != 0)
            {
                using (ManagementObjectCollection.ManagementObjectEnumerator managementObjectEnumerator = managementObjectCollection.GetEnumerator())
                {
                    if (managementObjectEnumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)managementObjectEnumerator.Current;
                        managementObject.InvokeMethod("RenamePrinter", new object[1]
                        {
                            newName
                        });
                    }
                }
            }
        }
コード例 #3
0
        public static string GetIPAddress()
        {
            ManagementObjectCollection objects;
            string          str    = "";
            ManagementClass class2 = new ManagementClass("Win32_NetworkAdapterConfiguration");

            using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = class2.GetInstances().GetEnumerator())
            {
                ManagementObject current;
                Array            array;
                while (enumerator.MoveNext())
                {
                    current = (ManagementObject)enumerator.Current;
                    if ((bool)current["IPEnabled"])
                    {
                        goto Label_004F;
                    }
                }
                goto Label_0089;
Label_004F:
                array = (Array)current.Properties["IpAddress"].Value;
                str   = array.GetValue(0).ToString();
            }
Label_0089:
            objects = null;
            class2  = null;
            return(str);
        }
コード例 #4
0
        /// <summary>
        /// Set the slidebar status. Just like SetAppRegistration.
        /// This function is also written by DOSSTONED
        /// </summary>
        /// <param name="evt">Event to set.</param>
        /// <param name="enabled">Whether this event is enabled.</param>
        public byte[] SetSlideBarStatus(Event evt, bool enabled)
        {
            byte[] array = new byte[128];
            array[0]  = 1;
            array[1]  = 16;
            array[8]  = (byte)evt;
            array[9]  = 3;
            array[10] = 0;
            array[16] = (byte)(enabled ? 1 : 0);
            array[68] = (byte)(enabled ? 1 : 0);

            SelectQuery              query = new SelectQuery("WMIACPI_IO");
            ManagementScope          scope = new ManagementScope("root\\WMI");
            ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(scope, query);

            using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    ManagementObject managementObject = (ManagementObject)enumerator.Current;
                    managementObject.SetPropertyValue("IOBytes", array);
                    managementObject.Put();
                }
            }
            if (managementObjectSearcher != null)
            {
                managementObjectSearcher.Dispose();
            }
            return(array);
        }
コード例 #5
0
        public static string GetMACAddress()
        {
            ManagementClass            mc  = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc = mc.GetInstances();
            string MACAddress = string.Empty;

            try
            {
                ManagementObjectCollection.ManagementObjectEnumerator enumerator = moc.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ManagementObject mo = (ManagementObject)enumerator.Current;
                    if (Operators.CompareString(MACAddress, string.Empty, false) == 0 && Conversions.ToBoolean(mo["IPEnabled"]))
                    {
                        MACAddress = mo["MacAddress"].ToString();
                    }
                    mo.Dispose();
                }
            }
            finally
            {
                ManagementObjectCollection.ManagementObjectEnumerator enumerator;
                if (enumerator != null)
                {
                    ((IDisposable)enumerator).Dispose();
                }
            }
            MACAddress = MACAddress.Replace(":", "");
            return(MACAddress);
        }
コード例 #6
0
        /// <summary>
        /// Gets an array of serial port names and descriptions for the current computer.
        /// </summary>
        /// <remarks>
        /// This method uses the Windows Management Interface to obtain its information. Therefore,
        /// the list may be different to the list obtained using the GetPortNames() method which
        /// uses other techniques.
        /// <para>On Windows 7, this method shows to return normal COM ports, but not those
        /// associated with a modem driver.</para>
        /// </remarks>
        /// <returns>An array of serial ports for the current computer.</returns>
        public PortDescription[] GetPortDescriptions()
        {
            Dictionary <string, PortDescription> list = new Dictionary <string, PortDescription>();

            using (RegistryKey local = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DEVICEMAP\SERIALCOMM", false)) {
                if (local != null)
                {
                    string[] k = local.GetValueNames();
                    foreach (string p in k)
                    {
                        string n = local.GetValue(p) as string;
                        list.Add(n, new PortDescription(n, ""));
                    }
                }
            }

#if !NETSTANDARD2_0
            ManagementObjectCollection objects;
            // Look for standard serial ports
            using (ManagementObjectSearcher q = new ManagementObjectSearcher("select * from Win32_SerialPort")) {
                objects = q.Get();
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = objects.GetEnumerator()) {
                    while (enumerator.MoveNext())
                    {
                        ManagementObject current = (ManagementObject)enumerator.Current;
                        string           k       = current["DeviceID"].ToString();
                        if (list.ContainsKey(k))
                        {
                            list[k].Description = current["Name"].ToString();
                        }
                    }
                }
            }

            // Look for any modems that are attached to COM ports that aren't listed above
            using (ManagementObjectSearcher q = new ManagementObjectSearcher("select * from Win32_POTSModem")) {
                objects = q.Get();
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = objects.GetEnumerator()) {
                    while (enumerator.MoveNext())
                    {
                        ManagementObject current = (ManagementObject)enumerator.Current;
                        string           k       = current["AttachedTo"].ToString();
                        if (list.ContainsKey(k))
                        {
                            list[k].Description = current["Name"].ToString();
                        }
                    }
                }
            }
#endif

            // Get the array and return it
            int i = 0;
            PortDescription[] ports = new PortDescription[list.Count];
            foreach (PortDescription p in list.Values)
            {
                ports[i++] = p;
            }
            return(ports);
        }
コード例 #7
0
        // Token: 0x0600051D RID: 1309 RVA: 0x00052728 File Offset: 0x00050928
        public string GetHardDiskID()
        {
            string result;

            try
            {
                ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
                string text = null;
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        text = managementObject["SerialNumber"].ToString().Trim();
                    }
                }
                if (text.Length % 2 != 0)
                {
                    text += " ";
                }
                char[]        array         = text.ToCharArray();
                StringBuilder stringBuilder = new StringBuilder();
                for (int i = 0; i < array.Length / 2; i++)
                {
                    stringBuilder.Append(array[2 * i + 1]);
                    stringBuilder.Append(array[2 * i]);
                }
                result = stringBuilder.ToString().Trim();
            }
            catch
            {
                result = "";
            }
            return(result);
        }
コード例 #8
0
        public static List <PortInfo> GetPortsInfo()
        {
            List <PortInfo>          portsInfo = new List <PortInfo>();
            ConnectionOptions        options   = Conexion.ProcessConnectionOptions();
            ManagementScope          scope     = Conexion.ConnectionScope(Environment.MachineName, options, "\\root\\CIMV2");
            ObjectQuery              query     = new ObjectQuery("SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0");
            ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(scope, query);

            using (managementObjectSearcher)
            {
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        if (managementObject != null)
                        {
                            object obj = managementObject["Caption"];
                            if (obj != null)
                            {
                                String str = obj.ToString();
                                if (str.Contains("(COM"))
                                {
                                    portsInfo.Add(new PortInfo {
                                        Name        = str.Substring(str.LastIndexOf("(COM")).Replace("(", String.Empty).Replace(")", String.Empty),
                                        Description = str
                                    });
                                }
                            }
                        }
                    }
                }
            }
            return(portsInfo);
        }
コード例 #9
0
        private byte[] ReadWMIACPI_IO()
        {
            byte[] result;
            try
            {
                ManagementScope          scope = new ManagementScope(this.WMIACPINamespace);
                SelectQuery              query = new SelectQuery(this.WMIACPIIOClass);
                ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(scope, query);
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        result = (byte[])managementObject["IOBytes"];
                        return(result);
                    }
                }
            }
            catch (ManagementException arg_69_0)
            {
                ManagementException ex = arg_69_0;
                //base.DebugInfoTrace(ex);
            }
            catch (Exception arg_75_0)
            {
                Exception ex2 = arg_75_0;
                //base.DebugInfoTrace(ex2);
            }
            return(null);

            return(result);
        }
コード例 #10
0
ファイル: Computer.cs プロジェクト: myonhu/PEIS-PEIS
        public static string GetTotalPhysicalMemory()
        {
            string result;

            try
            {
                string                     text            = "";
                ManagementClass            managementClass = new ManagementClass("Win32_ComputerSystem");
                ManagementObjectCollection instances       = managementClass.GetInstances();
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        text = managementObject["TotalPhysicalMemory"].ToString();
                    }
                }
                result = text;
            }
            catch
            {
                result = "unknow";
            }
            finally
            {
            }
            return(result);
        }
コード例 #11
0
        private static bool WriteWMIACPI_IO(byte place8, WMIACPI_IO_Status status)
        {
            byte[] array = new byte[128];
            array[0]  = 1;
            array[1]  = 16;
            array[8]  = place8;
            array[9]  = 3;
            array[10] = 0;
            array[16] = (byte)status;

            SelectQuery              query = new SelectQuery("WMIACPI_IO");
            ManagementScope          scope = new ManagementScope("root\\WMI");
            ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(scope, query);

            using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    ManagementObject managementObject = (ManagementObject)enumerator.Current;
                    managementObject.SetPropertyValue("IOBytes", array);
                    managementObject.Put();

                    return(true);
                }
            }
            if (managementObjectSearcher != null)
            {
                managementObjectSearcher.Dispose();
            }

            return(false);
        }
コード例 #12
0
ファイル: Computer.cs プロジェクト: myonhu/PEIS-PEIS
        public static string GetDiskID()
        {
            string result;

            try
            {
                string                     text            = "";
                ManagementClass            managementClass = new ManagementClass("Win32_DiskDrive");
                ManagementObjectCollection instances       = managementClass.GetInstances();
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        text = (string)managementObject.Properties["Model"].Value;
                    }
                }
                result = text;
            }
            catch
            {
                result = "unknow";
            }
            finally
            {
            }
            return(result);
        }
コード例 #13
0
ファイル: Computer.cs プロジェクト: myonhu/PEIS-PEIS
        public static string GetBaseBoard()
        {
            string result;

            try
            {
                List <string>            list = new List <string>();
                ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        string           text             = managementObject["SerialNumber"].ToString().Trim();
                        if (!string.IsNullOrEmpty(text))
                        {
                            list.Add(text);
                        }
                    }
                }
                if (list.Count > 0)
                {
                    list.Sort();
                    result = list[0];
                    return(result);
                }
            }
            catch
            {
            }
            result = string.Empty;
            return(result);
        }
コード例 #14
0
ファイル: Computer.cs プロジェクト: myonhu/PEIS-PEIS
        public static string GetIPAddress()
        {
            string result;

            try
            {
                string                     text            = "";
                ManagementClass            managementClass = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection instances       = managementClass.GetInstances();
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        if ((bool)managementObject["IPEnabled"])
                        {
                            System.Array array = (System.Array)managementObject.Properties["IpAddress"].Value;
                            text = array.GetValue(0).ToString();
                            break;
                        }
                    }
                }
                result = text;
            }
            catch
            {
                result = "unknow";
            }
            finally
            {
            }
            return(result);
        }
コード例 #15
0
        private static ManagementObject GetreceiveLocationWmiObject(string receiveLocation)
        {
            var searcher = new ManagementObjectSearcher();
            var scope    = new ManagementScope("root\\MicrosoftBizTalkServer");

            searcher.Scope = scope;

            // Build a Query to enumerate the MSBTS_ReceiveLocation instances if an argument
            // is supplied use it to select only the matching RL.
            var query = new SelectQuery
            {
                QueryString = String.Format("SELECT * FROM MSBTS_ReceiveLocation WHERE Name =\"{0}\"", receiveLocation)
            };

            // Set the query for the searcher.
            searcher.Query = query;

            // Execute the query and determine if any results were obtained.
            ManagementObjectCollection queryCol = searcher.Get();

            ManagementObjectCollection.ManagementObjectEnumerator me = queryCol.GetEnumerator();
            me.Reset();
            if (me.MoveNext())
            {
                return((ManagementObject)me.Current);
            }
            else
            {
                throw new ApplicationException(string.Format("The WMI object for the receive location:{0} could not be retrieved.", receiveLocation));
            }
        }
コード例 #16
0
ファイル: WMIUtils.cs プロジェクト: phspies/OculiService
    public static string GetPNPInstanceId(ManagementScope scope, int deviceId)
    {
        string empty = string.Empty;

        try
        {
            using (ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(scope, new ObjectQuery("Select * from Win32_NetworkAdapter Where DeviceID = " + deviceId.ToString())))
            {
                using (ManagementObjectCollection objectCollection = managementObjectSearcher.Get())
                {
                    using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = objectCollection.GetEnumerator())
                    {
                        if (enumerator.MoveNext())
                        {
                            empty = enumerator.Current["PNPDeviceID"].ToString();
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
        }
        return(empty);
    }
コード例 #17
0
ファイル: SystemHelper.cs プロジェクト: KleinPan/One
        /// <summary> 获取系统内存大小 </summary>
        /// <returns> 内存大小(单位M) </returns>
        public string GetPhisicalMemory()
        {
            //用于查询一些如系统信息的管理对象
            ManagementObjectSearcher searcher = new ManagementObjectSearcher();

            searcher.Query = new SelectQuery(WindowsAPIType.Win32_PhysicalMemory.ToString(), "", new string[] { WindowsAPIKeys.Capacity.ToString() }); //设置查询条件
            ManagementObjectCollection collection = searcher.Get();                                                                                    //获取内存容量

            ManagementObjectCollection.ManagementObjectEnumerator em = collection.GetEnumerator();

            long capacity = 0;

            while (em.MoveNext())
            {
                ManagementBaseObject baseObj = em.Current;
                if (baseObj.Properties[WindowsAPIKeys.Capacity.ToString()].Value != null)
                {
                    try
                    {
                        capacity += long.Parse(baseObj.Properties[WindowsAPIKeys.Capacity.ToString()].Value.ToString());
                    }
                    catch
                    {
                        return("查询失败");
                    }
                }
            }
            return(ToGB(capacity, 1024.0));
        }
コード例 #18
0
ファイル: StringHelper.cs プロジェクト: dengliyan/XUtils
        public static string GetNetCardMAC()
        {
            string result;

            try
            {
                string                     text            = "";
                ManagementClass            managementClass = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection instances       = managementClass.GetInstances();
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        if ((bool)managementObject["IPEnabled"])
                        {
                            text += managementObject["MACAddress"].ToString();
                        }
                    }
                }
                result = text;
            }
            catch
            {
                result = "";
            }
            return(result);
        }
コード例 #19
0
        // Token: 0x0600051C RID: 1308 RVA: 0x0005268C File Offset: 0x0005088C
        public string GetCpuID()
        {
            string result;

            try
            {
                ManagementClass            managementClass = new ManagementClass("Win32_Processor");
                ManagementObjectCollection instances       = managementClass.GetInstances();
                string text = null;
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        text = managementObject.Properties["ProcessorId"].Value.ToString();
                    }
                }
                result = text;
            }
            catch
            {
                result = "";
            }
            return(result);
        }
コード例 #20
0
        // Token: 0x06000B4E RID: 2894 RVA: 0x0003F324 File Offset: 0x0003D524
        private static string GetUIDFromWMI(string sysDrive)
        {
            ManagementObjectSearcher   managementObjectSearcher   = new ManagementObjectSearcher("SELECT * \r\n                                     FROM   Win32_Volume\r\n                                     WHERE  DriveLetter = '" + sysDrive + "'");
            ManagementObjectCollection managementObjectCollection = managementObjectSearcher.Get();
            string text = null;

            using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectCollection.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ManagementObject managementObject = (ManagementObject)enumerator.Current;
                    if (text != null)
                    {
                        break;
                    }
                    object propertyValue = managementObject.GetPropertyValue("DeviceID");
                    if (propertyValue != null)
                    {
                        text = propertyValue.ToString();
                    }
                    text.Substring(text.IndexOf('{') + 1).TrimEnd(new char[]
                    {
                        '\\'
                    }).TrimEnd(new char[]
                    {
                        '}'
                    });
                }
            }
            return(text);
        }
コード例 #21
0
 /// <summary>
 /// Write the bytes into WMIACPI_IO
 /// changed to public due to debug.
 /// </summary>
 /// <param name="ioBytes">Raw bytes, length = 128</param>
 /// <returns>True if success.</returns>
 public bool WriteWMIACPI_IO(byte[] ioBytes)
 {
     try
     {
         if (ioBytes.GetLength(0) != (int)this.IOBytesLength)
         {
             bool result = false;
             return(result);
         }
         SelectQuery              query = new SelectQuery(this.WMIACPIIOClass);
         ManagementScope          scope = new ManagementScope(this.WMIACPINamespace);
         ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(scope, query);
         using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectSearcher.Get().GetEnumerator())
         {
             if (enumerator.MoveNext())
             {
                 ManagementObject managementObject = (ManagementObject)enumerator.Current;
                 managementObject.SetPropertyValue("IOBytes", ioBytes);
                 managementObject.Put();
                 bool result = true;
                 return(result);
             }
         }
     }
     catch (ManagementException)
     {
     }
     return(false);
 }
コード例 #22
0
        public static string ServerIP()
        {
            string text = HttpContext.Current.Request.ServerVariables.Get("Local_Addr").ToString();

            if (text.Length < 7)
            {
                ManagementClass            managementClass = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection instances       = managementClass.GetInstances();
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        if ((bool)managementObject["IPEnabled"])
                        {
                            string[] array = (string[])managementObject["IPAddress"];
                            if (array.Length > 0)
                            {
                                text = array[0];
                            }
                            break;
                        }
                    }
                }
            }
            return(text);
        }
コード例 #23
0
ファイル: SystemInformation.cs プロジェクト: ni-xue/Tool.Net
        /// <summary>
        /// 获取系统内存大小(单位M)
        /// </summary>
        /// <returns>内存大小(单位M)</returns>
        public static int GetPhisicalMemory()
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher();                         //用于查询一些如系统信息的管理对象

            searcher.Query = new SelectQuery("Win32_PhysicalMemory ", "", new string[] { "Capacity" }); //设置查询条件
            ManagementObjectCollection collection = searcher.Get();                                     //获取内存容量

            ManagementObjectCollection.ManagementObjectEnumerator em = collection.GetEnumerator();

            long capacity = 0;

            while (em.MoveNext())
            {
                ManagementBaseObject baseObj = em.Current;
                if (baseObj.Properties["Capacity"].Value != null)
                {
                    try
                    {
                        capacity += long.Parse(baseObj.Properties["Capacity"].Value.ToString());
                    }
                    catch
                    {
                        return(0);
                    }
                }
            }
            return((int)(capacity / 1024 / 1024));
        }
コード例 #24
0
 public WMI(string path)
 {
     this.names = new StringDictionary();
     this.mocs  = new ArrayList();
     try
     {
         ManagementClass            managementClass = new ManagementClass(path);
         ManagementObjectCollection instances       = managementClass.GetInstances();
         bool flag = false;
         using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 ManagementObject managementObject = (ManagementObject)enumerator.Current;
                 Hashtable        hashtable        = new Hashtable();
                 this.mocs.Add(hashtable);
                 foreach (PropertyData current in managementObject.Properties)
                 {
                     hashtable.Add(current.Name, current.Value);
                     if (!flag)
                     {
                         this.names.Add(current.Name, current.Name);
                     }
                 }
                 flag = true;
                 managementObject.Dispose();
             }
         }
         instances.Dispose();
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
コード例 #25
0
        public static string GetCPUId()
        {
            string                     cpuInfo = string.Empty;
            string                     temp    = string.Empty;
            ManagementClass            mc      = new ManagementClass("Win32_Processor");
            ManagementObjectCollection moc     = mc.GetInstances();

            try
            {
                ManagementObjectCollection.ManagementObjectEnumerator enumerator = moc.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ManagementObject mo = (ManagementObject)enumerator.Current;
                    if (Operators.CompareString(cpuInfo, string.Empty, false) == 0)
                    {
                        cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
                    }
                }
            }
            finally
            {
                ManagementObjectCollection.ManagementObjectEnumerator enumerator;
                if (enumerator != null)
                {
                    ((IDisposable)enumerator).Dispose();
                }
            }
            return(cpuInfo);
        }
コード例 #26
0
        internal ManagementObject GetWmiObject(string className, string filter, params object[] args)
        {
            ManagementObjectCollection col = GetWmiObjects(className, filter, args);

            ManagementObjectCollection.ManagementObjectEnumerator enumerator = col.GetEnumerator();
            return(enumerator.MoveNext() ? (ManagementObject)enumerator.Current : null);
        }
コード例 #27
0
        public static string GetHardDiskID2()
        {
            var strHardDiskID = string.Empty;
            ManagementObjectSearcher wmiSearcher = new ManagementObjectSearcher();

            /*
             * 1. 接口
             * 2. 型号
             * 3. 驱动版本号
             * 4. 硬盘出厂序列号
             */
            //signature 需要程序以管理员身份运行
            try
            {
                wmiSearcher.Query = new SelectQuery("Win32_DiskDrive", "", new string[] { "PNPDeviceID", "signature" });
                ManagementObjectCollection myCollection = wmiSearcher.Get();
                ManagementObjectCollection.ManagementObjectEnumerator em = myCollection.GetEnumerator();
                myCollection.GetEnumerator();
                em.MoveNext();
                ManagementBaseObject mo = em.Current;
                strHardDiskID = mo.Properties["signature"].Value.ToString().Trim();
                return(strHardDiskID);
            }
            catch
            {
                return(string.Empty);
            }
        }
コード例 #28
0
ファイル: Form1.cs プロジェクト: xyzlun/ProcessMonitor
        private static int GetPhisicalMemory()
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher();                        //用于查询一些如系统信息的管理对象

            searcher.Query = new SelectQuery("Win32_PhysicalMemory", "", new string[] { "Capacity" }); //设置查询条件
            ManagementObjectCollection collection = searcher.Get();                                    //获取内存容量

            ManagementObjectCollection.ManagementObjectEnumerator em = collection.GetEnumerator();

            int capacity = 0;

            while (em.MoveNext())
            {
                ManagementBaseObject baseObj = em.Current;
                if (baseObj.Properties["Capacity"].Value != null)
                {
                    try
                    {
                        capacity += int.Parse(baseObj.Properties["Capacity"].Value.ToString());
                    }
                    catch
                    {
                        Console.WriteLine("有错误发生!", "错误信息");
                        return(0);
                    }
                }
            }
            return(capacity);
        }
コード例 #29
0
        private void InitFromHostApp()
        {
            ProgramArgumentCollection coll = new ProgramArgumentCollection();

            if (coll.ArgumentExists("--program"))
            {
                parentExecutable = coll["--program"];
            }
            else
            {
                string wmiQuery = string.Format("SELECT * FROM Win32_Process WHERE ProcessId = {0}", Process.GetCurrentProcess().Id);
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", wmiQuery);
                ManagementObjectCollection.ManagementObjectEnumerator mColl = searcher.Get().GetEnumerator();
                mColl.MoveNext();

                parentExecutable = (string)mColl.Current["ExecutablePath"];
            }

            FileVersionInfo info = FileVersionInfo.GetVersionInfo(parentExecutable);

            if (info.ProductName == null || info.ProductName == string.Empty)
            {
                appName = Path.GetFileNameWithoutExtension(parentExecutable);
            }
            else
            {
                appName = info.ProductName;
            }

            Text = "LangLib - Database configuration  [" + appName + "]";
        }
コード例 #30
0
ファイル: Win32.cs プロジェクト: skyclub66/HMI
        private static string GetMotherBoardSerialNumber()
        {
            string result;

            try
            {
                string                     text            = "";
                ManagementClass            managementClass = new ManagementClass("WIN32_BaseBoard");
                ManagementObjectCollection instances       = managementClass.GetInstances();
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)enumerator.Current;
                        text = managementObject["SerialNumber"].ToString().Trim();
                        if (text != "")
                        {
                            break;
                        }
                    }
                }
                if (text == "")
                {
                    text = "0000";
                }
                result = text;
            }
            catch
            {
                result = "0000";
            }
            return(result);
        }