GetGuestServiceInterfaceComponent( ManagementScope scope, string vmName) { ManagementObject guestServiceInterfaceComponent; using (ManagementObject virtualMachine = WmiUtilities.GetVirtualMachine( vmName, scope)) { using (ManagementObjectCollection settingsCollection = virtualMachine.GetRelated( "Msvm_GuestServiceInterfaceComponent", "Msvm_SystemDevice", null, null, null, null, false, null)) { guestServiceInterfaceComponent = WmiUtilities.GetFirstObjectFromCollection( settingsCollection); } } return(guestServiceInterfaceComponent); }
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); }
FileServerStatusConfirm(ManagementScope scope, ManagementObject managementService, string vmName) { using (ManagementObject guestServiceInterfaceComponent = GetGuestServiceInterfaceComponent(scope, vmName)) using (ManagementObject guestFileService = GetGuestFileService(guestServiceInterfaceComponent)) { if (Convert.ToUInt16(guestFileService.GetPropertyValue("EnabledState")) != 2) { using (ManagementObjectCollection guestServiceInterfaceComponentSettingDatas = guestServiceInterfaceComponent.GetRelated("Msvm_GuestServiceInterfaceComponentSettingData")) using (ManagementObject guestServiceInterfaceComponentSettingData = WmiUtilities.GetFirstObjectFromCollection(guestServiceInterfaceComponentSettingDatas)) { guestServiceInterfaceComponentSettingData["EnabledState"] = 2; using (ManagementBaseObject inParams = managementService.GetMethodParameters("ModifyResourceSettings")) { inParams["ResourceSettings"] = new string[] { guestServiceInterfaceComponentSettingData.GetText(TextFormat.WmiDtd20) }; using (ManagementBaseObject outParams = managementService.InvokeMethod( "ModifyResourceSettings", inParams, null)) { try { WmiUtilities.ValidateOutput(outParams, scope); } catch (ManagementException e) { Console.WriteLine("WMIÎļþ¿½±´Òì³££º" + e.Message); } } } } } } }