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


C# ManagementObject.GetRelated方法代码示例

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


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

示例1: GetResourceAllocationsettingData

        public static ManagementObject GetResourceAllocationsettingData(
            ManagementObject vm,
            ushort resourceType,
            string resourceSubType,
            string otherResourceType)
        {
            // vm->vmsettings->RASD for IDE controller
            ManagementObject managementObjectRASD = null;
            ManagementObjectCollection settingDatas = vm.GetRelated("Msvm_VirtualSystemsettingData");
            foreach (ManagementObject settingData in settingDatas)
            {
                // retrieve the rasd
                ManagementObjectCollection collectionOfRASDs = settingData.GetRelated("Msvm_ResourceAllocationsettingData");
                foreach (ManagementObject rasdInstance in collectionOfRASDs)
                {
                    if (Convert.ToInt16(rasdInstance["ResourceType"], CultureInfo.InvariantCulture) == resourceType)
                    {
                        // found the matching type
                        if (resourceType == ResourceType.Other)
                        {
                            if (rasdInstance["OtherResourceType"].ToString() == otherResourceType)
                            {
                                managementObjectRASD = rasdInstance;
                                break;
                            }
                        }
                        else
                        {
                            if (rasdInstance["ResourceSubType"].ToString() == resourceSubType)
                            {
                                managementObjectRASD = rasdInstance;
                                break;
                            }
                        }
                    }
                }
            }

            return managementObjectRASD;
        }
开发者ID:KjartanThor,项目名称:CustomActivities,代码行数:40,代码来源:Utility.cs

示例2: GetSnapshotData

        /// <summary>
        /// Gets the data for a given snapshot that belongs to the given virtual machine..
        /// </summary>
        /// <param name="virtualMachine">The virtual machine object.</param>
        /// <param name="snapshotName">The name of the snapshot that should be obtained.</param>
        /// <returns>The snapshot data object or <see langword="null" /> if no snapshot could be found.</returns>
        public static ManagementObject GetSnapshotData(ManagementObject virtualMachine, string snapshotName)
        {
            ManagementObjectCollection vmSettings = virtualMachine.GetRelated(
                "Msvm_VirtualSystemsettingData",
                "Msvm_PreviousSettingData",
                null,
                null,
                "SettingData",
                "ManagedElement",
                false,
                null);

            ManagementObject vmSetting = null;
            foreach (ManagementObject instance in vmSettings)
            {
                var name = (string)instance["ElementName"];
                if (string.Equals(snapshotName, name, StringComparison.Ordinal))
                {
                    vmSetting = instance;
                    break;
                }
            }

            return vmSetting;
        }
开发者ID:pvandervelde,项目名称:Sherlock,代码行数:31,代码来源:WmiUtility.cs

示例3: 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

示例4: GetReplicationServiceSettings

        GetReplicationServiceSettings(
            ManagementObject replicationService)
        {
            using (ManagementObjectCollection settingsCollection =
                    replicationService.GetRelated("Msvm_ReplicationServiceSettingData"))
            {
                ManagementObject replicationServiceSettings = 
                    WmiUtilities.GetFirstObjectFromCollection(settingsCollection);

                return replicationServiceSettings;
            }
        }
开发者ID:dhanzhang,项目名称:Windows-classic-samples,代码行数:12,代码来源:ReplicaUtilities.cs

示例5: getDisk

 public static Disk getDisk(string driveLetter)
 {
     var disks = new ManagementObject("Win32_LogicalDisk.DeviceID='" + driveLetter + ":'");
     foreach (ManagementObject diskPart in disks.GetRelated("Win32_DiskPartition"))
     {
         foreach (ManagementObject diskDrive in diskPart.GetRelated("Win32_DiskDrive"))
         {
             Disk disk = new Disk();
             disk.driveLetter = driveLetter;
             disk.productName = diskDrive["Caption"].ToString().Replace(" ATA Device", "");
             disk.pnpId = diskDrive["PnPDeviceID"].ToString();
             return disk;
         }
     }
     return null;
 }
开发者ID:m-ober,项目名称:SSDStressTest,代码行数:16,代码来源:WmiTools.cs

示例6: GetSerialNumber

        public static string GetSerialNumber(string DriveLetter)
        {
            DriveLetter = DriveLetter.ToUpper();
            string  temp = string.Empty;
            string ans = string.Empty;
            string[] parts;
            //get the Logical Disk for that drive letter
            ManagementObject wmi_ld = new ManagementObject("win32_logicaldisk.deviceid=\"" + DriveLetter + "\"");
            //get the associated DiskPartition
            foreach (ManagementObject DiskPartition in wmi_ld.GetRelated("Win32_DiskPartition"))
            {
                //get the associated DiskDrive
                foreach (ManagementObject DiskDrive in DiskPartition.GetRelated("Win32_DiskDrive"))
                {
                    /*There is a bug in WinVista that corrupts some of the fields
                    of the Win32_DiskDrive class if you instantiate the class via
                    its primary key (as in the example above) and the device is
                    a USB disk. Oh well... so we have go thru this extra step*/
                    ManagementClass wmi = new ManagementClass("Win32_DiskDrive");
                    /*loop thru all of the instances. This is silly, we shouldn't
                     *have to loop thru them all, when we know which one we want.*/
                    foreach (ManagementObject obj in wmi.GetInstances())
                    {
                        // do the DeviceID fields match?
                        if (obj["DeviceID"].ToString() == DiskDrive["DeviceID"].ToString())
                        {
                            //the serial number is embedded in the PnPDeviceID
                            temp = obj["PnPDeviceID"].ToString();
                            if (!temp.StartsWith("USBSTOR"))
                            {
                                System.Windows.Forms.MessageBox.Show(DriveLetter + " doesn't appear to be USB Device");
                                return string.Empty;
                            }
                            parts = temp.Split("\\&".ToCharArray());
                            //The serial number should be the next to the last element
                            ans = parts[parts.Length - 2];
                        }

                    }
                }
            }
            return ans;
        }
开发者ID:EgyFalseX-EESoft-WinForm,项目名称:ATCommands,代码行数:43,代码来源:USBSerialNumber.cs

示例7: GetDefaultObjectFromResourcePool

        GetDefaultObjectFromResourcePool(
            ManagementObject resourcePool,
            ManagementScope scope)
        {
            //
            // The default object is associated with the Msvm_AllocationCapabilities object that 
            // is associated to the resource pool.
            //
            string defaultSettingPath = null;

            using (ManagementObjectCollection capabilitiesCollection = 
                   resourcePool.GetRelated("Msvm_AllocationCapabilities",
                                           "Msvm_ElementCapabilities",
                                           null, null, null, null, false, null))
            using (ManagementObject capabilities =
                   WmiUtilities.GetFirstObjectFromCollection(capabilitiesCollection))
            {
                foreach (ManagementObject settingAssociation in 
                         capabilities.GetRelationships("Msvm_SettingsDefineCapabilities"))
                {
                    using (settingAssociation)
                    {
                        if ((ushort)settingAssociation["ValueRole"] == 0)
                        {
                            defaultSettingPath = (string)settingAssociation["PartComponent"];
                            break;
                        }
                    }
                }
            }

            if (defaultSettingPath == null)
            {
                throw new ManagementException(string.Format(CultureInfo.CurrentCulture,
                                                            "Unable to find the default settings!"));
            }

            ManagementObject defaultSetting = new ManagementObject(defaultSettingPath);
            defaultSetting.Scope = scope;
            defaultSetting.Get();

            return defaultSetting;
        }
开发者ID:dhanzhang,项目名称:Windows-classic-samples,代码行数:43,代码来源:FibreChannelUtilities.cs

示例8: GetGuestFileService

        GetGuestFileService(
            ManagementObject guestServiceInterfaceComponent)
        {
            ManagementObject guestFileService;

            using (ManagementObjectCollection guestFileServices =
                guestServiceInterfaceComponent.GetRelated(
                    "Msvm_GuestFileService",
                    "Msvm_RegisteredGuestService",
                    null,
                    null,
                    null,
                    null,
                    false,
                    null))
            {
                guestFileService = WmiUtilities.GetFirstObjectFromCollection(
                    guestFileServices);
            }

            return guestFileService;
        }
开发者ID:dhanzhang,项目名称:Windows-classic-samples,代码行数:22,代码来源:GuestServiceInterface.cs

示例9: GetMigrationServiceSettings

        GetMigrationServiceSettings(
            ManagementObject service
            )
        {
            ManagementObject serviceSetting = null;
            using (ManagementObjectCollection settingCollection =
                service.GetRelated("Msvm_VirtualSystemMigrationServiceSettingData"))
            {
                foreach (ManagementObject mgmtObj in settingCollection)
                {
                    serviceSetting = mgmtObj;
                    break;
                }
            }

            return serviceSetting;
        }
开发者ID:dhanzhang,项目名称:Windows-classic-samples,代码行数:17,代码来源:MigrationCommon.cs

示例10: GetReplicationRelationshipObject

        GetReplicationRelationshipObject(
            ManagementObject virtualMachine,
            UInt16 relationshipType)
        {
            if (relationshipType > 1)
            {
                throw new ArgumentException("Replication relationship should be either 0 or 1");
            }

            using (ManagementObjectCollection relationshipCollection = 
                virtualMachine.GetRelated("Msvm_ReplicationRelationship"))
            {
                if (relationshipCollection.Count == 0)
                {
                    throw new ManagementException(
                        "No Msvm_ReplicationRelationship instance could be found");
                }

                //
                // Return the relationship instance whose InstanceID ends with given relationship type.
                //
                foreach (ManagementObject relationshipObject in relationshipCollection)
                {
                    string instanceID = relationshipObject.GetPropertyValue("InstanceID").ToString();
                    if (instanceID.EndsWith(relationshipType.ToString(CultureInfo.CurrentCulture), StringComparison.CurrentCulture))
                    {
                        return relationshipObject;
                    }
                }
            }

            return null;
        }
开发者ID:dhanzhang,项目名称:Windows-classic-samples,代码行数:33,代码来源:ReplicaUtilities.cs

示例11: GetComputerKeyboard

        /// <summary>
        /// The get computer keyboard.
        /// </summary>
        /// <param name="vm">
        /// The vm.
        /// </param>
        /// <returns>
        /// The <see cref="ManagementObject"/>.
        /// </returns>
        private static ManagementObject GetComputerKeyboard(ManagementObject vm)
        {
            ManagementObjectCollection keyboardCollection = vm.GetRelated(
                "Msvm_Keyboard", "Msvm_SystemDevice", null, null, "PartComponent", "GroupComponent", false, null);

            ManagementObject keyboard = null;

            foreach (ManagementObject instance in keyboardCollection)
            {
                keyboard = instance;
                break;
            }

            return keyboard;
        }
开发者ID:Expensify,项目名称:WindowsPhoneTestFramework,代码行数:24,代码来源:Win8EmulatorWindowsPhoneDeviceController.cs

示例12: GetRelatedWmiObject

 internal ManagementObject GetRelatedWmiObject(ManagementObject obj, string className)
 {
     ManagementObjectCollection col = obj.GetRelated(className);
     ManagementObjectCollection.ManagementObjectEnumerator enumerator = col.GetEnumerator();
     enumerator.MoveNext();
     return (ManagementObject)enumerator.Current;
 }
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:7,代码来源:Wmi.cs

示例13: GetImportedPvm

        GetImportedPvm(
            ManagementBaseObject outputParameters)
        {
            ManagementObject pvm = null;
            ManagementScope scope = new ManagementScope(@"root\virtualization\v2");

            if (WmiUtilities.ValidateOutput(outputParameters, scope))
            {
                if ((uint)outputParameters["ReturnValue"] == 0)
                {
                    pvm = new ManagementObject((string)outputParameters["ImportedSystem"]);
                }
                
                if ((uint)outputParameters["ReturnValue"] == 4096)
                {
                    using (ManagementObject job = 
                        new ManagementObject((string)outputParameters["Job"]))
                    using (ManagementObjectCollection pvmCollection = 
                        job.GetRelated("Msvm_PlannedComputerSystem",
                            "Msvm_AffectedJobElement", null, null, null, null, false, null))
                    {
                        pvm = WmiUtilities.GetFirstObjectFromCollection(pvmCollection);
                    }

                }
            }

            return pvm;
        }
开发者ID:dhanzhang,项目名称:Windows-classic-samples,代码行数:29,代码来源:ImportUtilities.cs

示例14: GetVirtualSystemSettingData

        public static ManagementObject GetVirtualSystemSettingData(ManagementObject vm)
        {
            ManagementObject virtualMachineSetting = null;
            ManagementObjectCollection virtualMachineSettings = vm.GetRelated(
                "Msvm_VirtualSystemSettingData",
                "Msvm_SettingsDefineState",
                null,
                null,
                "SettingData",
                "ManagedElement",
                false,
                null);

            if (virtualMachineSettings.Count != 1)
            {
                throw new Exception(string.Format(CultureInfo.InvariantCulture, "{0} instance of Msvm_VirtualSystemSettingData was found", virtualMachineSettings.Count));
            }

            foreach (ManagementObject instance in virtualMachineSettings)
            {
                virtualMachineSetting = instance;
                break;
            }

            return virtualMachineSetting;
        }
开发者ID:KjartanThor,项目名称:CustomActivities,代码行数:26,代码来源:Utility.cs

示例15: PrintOutOfPolicyVHDsInPool

        PrintOutOfPolicyVHDsInPool(
            ManagementObject resourcePool)
        {
            //Get Logical disks in the pool
            ManagementObjectCollection logicalDisks = resourcePool.GetRelated(
                "Msvm_LogicalDisk",
                "Msvm_ElementAllocatedFromPool",
                null, null, null, null, false, null);

            foreach (ManagementObject logicalDisk in logicalDisks)
            using (logicalDisk)
            {
                //Check the operational status on the logical disk
                UInt16[] opStatus = (UInt16[])logicalDisk["OperationalStatus"];
                if (opStatus[0] != OperationalStatusOK)
                {                            
                    foreach (UInt16 opState in opStatus)
                    {
                        //Check for the specific QOS related opcode
                        if (opState == OperationalStatusInsufficientThroughput)
                        {
                            // Get the SASD associated with the logical disk to get the vhd name.
                            using (ManagementObjectCollection sasds = logicalDisk.GetRelated(
                                "Msvm_StorageAllocationSettingData",
                                "Msvm_SettingsDefineState",
                                null, null, null, null, false, null))
                            // There is only one sasd associated with a logical disk.
                            foreach (ManagementObject sasd in sasds)
                            using (sasd)
                            {
                                string vhdPath = ((string[])sasd["HostResource"])[0];
                                string vhdName = Path.GetFileName(vhdPath);
                                Console.WriteLine("    VHD Not in Policy: {0}", vhdName);
                            }
                        }
                    }
                }
            }
        }
开发者ID:dhanzhang,项目名称:Windows-classic-samples,代码行数:39,代码来源:StorageQoS.cs


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