当前位置: 首页>>代码示例>>C#>>正文


C# ManagementObject.Str方法代码示例

本文整理汇总了C#中System.Management.ManagementObject.Str方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementObject.Str方法的具体用法?C# ManagementObject.Str怎么用?C# ManagementObject.Str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.ManagementObject的用法示例。


在下文中一共展示了ManagementObject.Str方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Volume

        // Expects a Win32_DiskDrive object
        // http://msdn.microsoft.com/en-us/library/aa394132%28v=VS.85%29.aspx
        internal Volume(ManagementObject o)
        {
            if (o.ClassPath.ClassName != "Win32_DiskDrive")
                throw new ArgumentException (o.ClassPath.ClassName, "o");

            Uuid = o.Str ("PNPDeviceID");
            Name = o.Str ("Caption");

            // Get USB vendor/product ids from the associated CIM_USBDevice
            // This way of associating them (via a substring of the PNPDeviceID) is quite a hack; patches welcome
            var match = regex.Match (Uuid);
            if (match.Success) {
                string query = String.Format ("SELECT * FROM CIM_USBDevice WHERE DeviceID LIKE '%{0}'", match.Groups[1].Captures[0].Value);
                UsbDevice = HardwareManager.Query (query).Select (u => new UsbDevice (u)).FirstOrDefault ();
            }

            // Get MountPoint and more from the associated LogicalDisk
            // FIXME this assumes one partition for the device
            foreach (ManagementObject partition in o.GetRelated ("Win32_DiskPartition")) {
                foreach (ManagementObject disk in partition.GetRelated ("Win32_LogicalDisk")) {
                    //IsMounted = (bool)ld.GetPropertyValue ("Automount") == true;
                    //IsReadOnly = (ushort) ld.GetPropertyValue ("Access") == 1;
                    MountPoint = disk.Str ("Name") + "/";
                    FileSystem = disk.Str ("FileSystem");
                    Capacity = (ulong) disk.GetPropertyValue ("Size");
                    Available = (long)(ulong)disk.GetPropertyValue ("FreeSpace");
                    return;
                }
            }
        }
开发者ID:kelsieflynn,项目名称:banshee,代码行数:32,代码来源:Volume.cs

示例2: UsbDevice

        // Expects a CIM_USBDevice object
        // http://msdn.microsoft.com/en-us/library/aa388649%28v=vs.85%29.aspx
        internal UsbDevice(ManagementObject o)
        {
            Uuid = o.Str ("DeviceID");
            UsbDevice = this;

            // Parse the vendor and product IDs out; best way I could find; patches welcome
            VendorId  = Int32.Parse (Uuid.Substring (Uuid.IndexOf ("VID_") + 4, 4), NumberStyles.HexNumber);
            ProductId = Int32.Parse (Uuid.Substring (Uuid.IndexOf ("PID_") + 4, 4), NumberStyles.HexNumber);
        }
开发者ID:kelsieflynn,项目名称:banshee,代码行数:11,代码来源:UsbDevice.cs


注:本文中的System.Management.ManagementObject.Str方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。