예제 #1
0
    public static int GetNumberOfCPUs(ManagementScope scope)
    {
        ManagementObject managementObject = WMIUtils.QueryFirst(scope, "Select * From Win32_ComputerSystem");
        object           propertyValue    = WMIUtils.GetPropertyValue((ManagementBaseObject)managementObject, "NumberOfLogicalProcessors");

        return(propertyValue == null ? (int)(uint)WMIUtils.GetPropertyValue((ManagementBaseObject)managementObject, "NumberOfProcessors") : (int)(uint)propertyValue);
    }
예제 #2
0
    public static OperatingSystemInfo GetOperatingSystemInfo(ManagementScope scope)
    {
        OperatingSystemInfo operatingSystemInfo = new OperatingSystemInfo();

        using (ManagementObject managementObject = WMIUtils.QueryFirst(scope, "Select * from Win32_OperatingSystem"))
        {
            string str = managementObject["Version"].ToString();
            if (!string.IsNullOrEmpty(str))
            {
                string[] strArray = str.Split(".".ToCharArray());
                operatingSystemInfo.VersionString = str;
                operatingSystemInfo.Version       = new OperatingSystemVersion()
                {
                    Major = Convert.ToInt32(strArray[0]),
                    Minor = Convert.ToInt32(strArray[1]),
                    Build = Convert.ToInt32(managementObject["BuildNumber"])
                };
            }
            operatingSystemInfo.ServicePack = string.Format("{0}.{1}.0.0", (object)Convert.ToInt32(managementObject["ServicePackMajorVersion"]).ToString(), (object)Convert.ToInt32(managementObject["ServicePackMinorVersion"]).ToString());
            operatingSystemInfo.ProductType = (OperatingSystemProductType)(uint)managementObject["ProductType"];
            if (managementObject["OSProductSuite"] != null)
            {
                operatingSystemInfo.ProductSuite = (int)(uint)managementObject["OSProductSuite"];
            }
            operatingSystemInfo.Architecture = WMIUtils.GetCPUArchitecture(scope, operatingSystemInfo.Version.Major);
        }
        return(operatingSystemInfo);
    }
예제 #3
0
 public ManagementObject QueryFirst(string query)
 {
     if (this._mo == null)
     {
         throw new HyperVException("ManagedElement not initialized");
     }
     return(WMIUtils.QueryFirst(this._mo.Scope, query));
 }
예제 #4
0
 public static void ComputerSystem(ManagementScope cimv2Scope, out string domain, out string domainRole)
 {
     using (ManagementObject managementObject = WMIUtils.QueryFirst(cimv2Scope, "select * from Win32_ComputerSystem"))
     {
         domain     = (string)managementObject["Domain"];
         domainRole = managementObject["DomainRole"].ToString();
     }
 }
예제 #5
0
 public static void GetOperatingSystemInfo(ManagementScope scope, ref OperatingSystemInfo OsInfo, ref string systemPath, ref string systemVolume)
 {
     OsInfo = WMIUtils.GetOperatingSystemInfo(scope);
     using (ManagementObject managementObject = WMIUtils.QueryFirst(scope, "Select * from Win32_OperatingSystem"))
     {
         systemPath   = managementObject["SystemDirectory"].ToString().Replace("\\system32", "");
         systemVolume = systemPath.Substring(0, 2);
     }
 }
예제 #6
0
    public static ManagementObject GetHDD(ManagementScope scope, HddLocation hddLocation)
    {
        string           query            = string.Format("Select * From Win32_DiskDrive Where SCSIBus={0} And SCSILogicalUnit={1} And SCSIPort={2} And SCSITargetId={3}", (object)hddLocation.Bus, (object)hddLocation.Lun, (object)hddLocation.Port, (object)hddLocation.Target);
        ManagementObject managementObject = WMIUtils.QueryFirst(scope, query);

        if (managementObject != null)
        {
            return(managementObject);
        }
        throw new ApplicationException("GetHDD failed with " + hddLocation.ToString());
    }
예제 #7
0
    public static VolumeInfo GetVolumeInfo(string volumeId)
    {
        VolumeInfo volumeInfo = new VolumeInfo();

        if (!volumeId.EndsWith("\\"))
        {
            volumeId += "\\";
        }
        ManagementObject managementObject = WMIUtils.QueryFirst(WMIUtils.ConnectToServer("localhost", (string)null, (string)null), "Select * From Win32_Volume Where DeviceID='" + volumeId.Replace("\\", "\\\\") + "'");

        volumeInfo.DiskSizeMB  = (long)(ulong)managementObject["Capacity"] / 1048576L;
        volumeInfo.FreeSpaceMB = (long)(ulong)managementObject["Freespace"] / 1048576L;
        volumeInfo.UsedSpaceMB = volumeInfo.DiskSizeMB - volumeInfo.FreeSpaceMB;
        volumeInfo.Format      = (string)managementObject["FileSystem"];
        volumeInfo.Label       = (string)managementObject["Label"];
        volumeInfo.DriveType   = (int)(uint)managementObject["DriveType"];
        return(volumeInfo);
    }
예제 #8
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)
             });
         }
     }
 }
예제 #9
0
 public static string GetSystemDirectory(ManagementScope cimv2Scope)
 {
     using (ManagementObject managementObject = WMIUtils.QueryFirst(cimv2Scope, "select * from win32_operatingsystem"))
         return((string)managementObject["SystemDirectory"]);
 }
예제 #10
0
 public static bool IsDTRachetInstalled(ManagementScope scope)
 {
     using (ManagementObject managementObject = WMIUtils.QueryFirst(scope, "Select * From WIN32_SystemDriver Where Name='RepDrv'"))
         return(managementObject != null);
 }