예제 #1
0
    public static string GetDriveLetterForNonSystemVolume(ManagementScope scope)
    {
        string empty = string.Empty;

        VolumeInfo[] volumes = SystemStateReader.GetVolumes(scope);
        return(volumes.Length <= 1 ? volumes[0].DriveLetter : volumes.ToList <VolumeInfo>().Find((Predicate <VolumeInfo>)(x => !x.IsSystemVolume)).DriveLetter);
    }
예제 #2
0
 public HostCfgInfo GetCfg(string address, string username, string password)
 {
     using (IVirtualSystemManagementService managmentService = VirtualSystemManagementService.GetVirtualSystemManagmentService(this._Host))
     {
         using (IVirtualSystemManagementServiceSettingData serviceSettingData = VirtualSystemManagementServiceSettingData.GetRelated(managmentService).FirstOrDefault <IVirtualSystemManagementServiceSettingData>())
         {
             ManagementScope  server           = WMIUtils.ConnectToServer(address, username, password);
             ManagementObject managementObject = WMIUtils.QueryFirst(server, "Select * From Win32_ComputerSystem");
             return(new HostCfgInfo()
             {
                 Name = this._Host.ElementName,
                 DefaultExternalDataRoot = serviceSettingData.DefaultExternalDataRoot,
                 DefaultVirtualHardDiskPath = serviceSettingData.DefaultVirtualHardDiskPath,
                 CpuNum = (long)(uint)WMIUtils.GetPropertyValue((ManagementBaseObject)managementObject, "NumberOfLogicalProcessors"),
                 Ram = (long)(ulong)WMIUtils.GetPropertyValue((ManagementBaseObject)managementObject, "TotalPhysicalMemory"),
                 Volumes = SystemStateReader.GetVolumes(server),
                 VirtualSwitches = this.GetAllVirtualSwitchesWithUuid().Values.Select <IVirtualSwitch, VirtualSwitchInfo>((Func <IVirtualSwitch, VirtualSwitchInfo>)(vs => vs.GetCfg())).ToList <VirtualSwitchInfo>(),
                 OsInfo = WMIUtils.GetOperatingSystemInfo(server)
             });
         }
     }
 }
예제 #3
0
    public static SystemState GetSystemState(ManagementScope scope, ManagementScope defaultScope, string serverName, ILogger logger)
    {
        SystemState systemState = new SystemState();

        try
        {
            systemState.RAM  = CUtils.RoundUp(WMIUtils.GetRAM(scope) / 1048576L);
            systemState.CPUs = WMIUtils.GetNumberOfCPUs(scope);
            WMIUtils.GetOperatingSystemInfo(scope, ref systemState.OsInfo, ref systemState.SystemPath, ref systemState.SystemVolume);
            try
            {
                string str = CUtils.PathToUNC(serverName, systemState.SystemPath) + "\\System32\\hal.dll";
                if (File.Exists(str))
                {
                    FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(str);
                    systemState.HalInternalName = versionInfo.InternalName;
                    systemState.HalVersion      = versionInfo.FileVersion;
                }
            }
            catch (Exception ex)
            {
                if (logger != null)
                {
                    logger.Verbose("Could not get Hal information. Exception: " + ex.Message, "SystemState");
                }
                throw;
            }
            try
            {
                systemState.ProgramFilesPath = WMIUtils.GetRemoteRegistryValueString(defaultScope, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "ProgramFilesDir");
            }
            catch (Exception ex)
            {
                if (logger != null)
                {
                    logger.Verbose("Could not get \"Program Files\" path. Exception: " + ex.Message, "SystemState");
                }
                throw;
            }
            try
            {
                systemState.NetworkAdapters = SystemStateReader.GetNetworkAdapterList(scope);
            }
            catch (Exception ex)
            {
                if (logger != null)
                {
                    logger.Verbose("Could not get the logical network adpater info from " + serverName + ". Exception: " + ex.Message, "SystemState");
                }
                throw;
            }
            try
            {
                systemState.Volumes = SystemStateReader.GetVolumes(scope);
            }
            catch (Exception ex)
            {
                if (logger != null)
                {
                    logger.Verbose("Could not get the volume info from " + serverName + ". Exception: " + ex.Message, "SystemState");
                }
                throw;
            }
        }
        catch (Exception ex)
        {
            if (logger != null)
            {
                logger.Verbose("Exception thrown getting the system state for server " + serverName + ". Exception: " + ex.Message, "SystemState");
            }
            throw;
        }
        return(systemState);
    }