如何查看机器类型? 笔记本电脑还是台式机?

发布于 2024-07-24 11:01:54 字数 1230 浏览 3 评论 0原文

如何查看当前机器类型? 笔记本电脑还是台式机?

我从 http://blog.csdn.net/antimatterworld 得到这个/archive/2007/11/11/1878710.aspx ,它在我的家用机器(笔记本电脑上的 Win2003)上运行良好,它返回“便携式”,但在我的工作机器(笔记本电脑上的 Vista)上失败,它返回“其他”。

这是代码:


public enum ChassisTypes
{
    Other = 1,
    Unknown,
    Desktop,
    LowProfileDesktop,
    PizzaBox,
    MiniTower,
    Tower,
    Portable,
    Laptop,
    Notebook,
    Handheld,
    DockingStation,
    AllInOne,
    SubNotebook,
    SpaceSaving,
    LunchBox,
    MainSystemChassis,
    ExpansionChassis,
    SubChassis,
    BusExpansionChassis,
    PeripheralChassis,
    StorageChassis,
    RackMountChassis,
    SealedCasePC
}

public static ChassisTypes GetCurrentChassisType()
{
    ManagementClass systemEnclosures = new ManagementClass("Win32_SystemEnclosure");
    foreach (ManagementObject obj in systemEnclosures.GetInstances())
    {
        foreach (int i in (UInt16[  ])(obj["ChassisTypes"]))
        {
             if (i > 0 && i < 25)
            {
                return (ChassisTypes)i;
            }
        }
    }
    return ChassisTypes.Unknown;
}

How to check current machine type? laptop or desktop ?

I got this from http://blog.csdn.net/antimatterworld/archive/2007/11/11/1878710.aspx ,it works well on my home machine(Win2003 on laptop), it returns "Portable", but failed on my work machine(Vista on laptop), it returns "Other".

here is the code:


public enum ChassisTypes
{
    Other = 1,
    Unknown,
    Desktop,
    LowProfileDesktop,
    PizzaBox,
    MiniTower,
    Tower,
    Portable,
    Laptop,
    Notebook,
    Handheld,
    DockingStation,
    AllInOne,
    SubNotebook,
    SpaceSaving,
    LunchBox,
    MainSystemChassis,
    ExpansionChassis,
    SubChassis,
    BusExpansionChassis,
    PeripheralChassis,
    StorageChassis,
    RackMountChassis,
    SealedCasePC
}

public static ChassisTypes GetCurrentChassisType()
{
    ManagementClass systemEnclosures = new ManagementClass("Win32_SystemEnclosure");
    foreach (ManagementObject obj in systemEnclosures.GetInstances())
    {
        foreach (int i in (UInt16[  ])(obj["ChassisTypes"]))
        {
             if (i > 0 && i < 25)
            {
                return (ChassisTypes)i;
            }
        }
    }
    return ChassisTypes.Unknown;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

毁虫ゝ 2024-07-31 11:01:54

好吧,我可能试图在这里复活死者,但我建议确定笔记本电脑的最可靠方法是盖子状态开关的存在。
请参阅 GetPwrCapabilitySystem_power_Capability

Well, I may be attempting to raise the dead here, but I would suggest that the most reliable method of determining a laptop would be the present of a lid status switch.
See GetPwrCapabilities and System_power_Capabilities

じее 2024-07-31 11:01:54

这是一篇很好的 Microsoft 文章,建议查看其他一些 WMI 类,以更好地了解计算机是笔记本电脑还是台式机:
http://technet.microsoft.com/en-us/library/cc180825.aspx

Win32_SystemEnclosure, ChassisTypes(1)=10
Win32_Battery or Win32_PortableBattery
Win32_PCMCIAController
Win32_DriverVXD.Name = "pccard"
Win32_ComputerSystem.Manufacturer
Win32_ComputerSystem.Model

它还建议在注册表中查找电源方案。

Here's a good Microsoft article that suggests looking at a few other WMI classes to get a better idea of whether the computer is a laptop or desktop:
http://technet.microsoft.com/en-us/library/cc180825.aspx

Win32_SystemEnclosure, ChassisTypes(1)=10
Win32_Battery or Win32_PortableBattery
Win32_PCMCIAController
Win32_DriverVXD.Name = "pccard"
Win32_ComputerSystem.Manufacturer
Win32_ComputerSystem.Model

And it also suggests to look in the registry for the Power scheme.

太阳公公是暖光 2024-07-31 11:01:54

无需同时进行其他未知检查。

将条件更改为 i > 1 && 我< 25 并记住 ChassisTypes 是一个数组,操作系统会返回他认为您的系统是什么的数组。

可以匹配多个单一类型。 您的代码仅返回第一个匹配项。

There is no need for both Other and Unknown check.

Change the condition to i > 1 && i < 25 and remember ChassisTypes is an array where OS returns what ever he thinks your system is.

It is possible to match more than single type. Your code only returns the first match.

百变从容 2024-07-31 11:01:54

请参阅 http://www.microsoft.com/technet/scriptcenter /resources/qanda/sept04/hey0921.mspxhttp://msdn.microsoft.com/en-us/library/aa387204(VS.85).aspx 其中指出:

本文档源自 DMTF 发布的 CIM 类描述。

据推测,这意味着制造商必须提供一些信息以便 Windows 能够发现它。

See http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept04/hey0921.mspx and http://msdn.microsoft.com/en-us/library/aa387204(VS.85).aspx which states that:

This documentation is derived from the CIM class descriptions published by the DMTF.

Presumably, that means the manufacturer had to provide some information for Windows to be able to discover it.

浅听莫相离 2024-07-31 11:01:54

我认为对此没有明确的正确答案,并且我发现 WMI 对此不可靠,但我一直在使用 Win32 函数 GetSystemPowerStatus() 来确定是否有系统电池,显然系统电池==便携式计算机。

我从来没有在带有 UPS 的台式机上尝试过这个?!

I don't think there is a definitive right answer for this and I've found WMI unreliable for it but I have been using the Win32 function GetSystemPowerStatus() to determine if there is a system battery, obviously system battery == portable computer.

I've never tried this on a desktop with a UPS though?!

柒七 2024-07-31 11:01:54

我非常确定这将取决于制造商是否愿意提供当前芯片组上的数据。 如果他们还没有,那么“其他”就是你能做的最好的事情。

查看这篇有些相关的文章,其中还建议< a href="http://www.codeguru.com/cpp/misc/misc/tools/article.php/c12347#Sample" rel="nofollow noreferrer">直接查询BIOS。

I am pretty sure that this will depend on whether the manufacturer has bothered to provide that data on the current chipset. If they have not, then "Other" is the best you can do.

Check out this somewhat related article, which also suggests querying the BIOS directly.

临风闻羌笛 2024-07-31 11:01:54

为了检查机器是笔记本电脑还是台式机,您可以尝试使用 SystemPowerCapabilites.LidPresent 或两者都检查电池状态。

电池:

if(SystemInformation.PowerStatus.BatteryChargeStatus ==BatteryChargeStatus.NoSystemBattery){
  //desktop 
}
else{
  //laptop
}

SystemPowerCapabilites.LidPresent:

public SYSTEM_POWER_CAPABILITIES getSystemPowerCapabilites(){
{
    SYSTEM_POWER_CAPABILITIES systemPowerCapabilites;
    GetPwrCapabilities(out systemPowerCapabilites);
    return systemPowerCapabilites;
}

getSystemPowerCapabilites().LidPresent;

GetPwrCapativity 定义:http://www.pinvoke.net/ default.aspx/powrprof/GetPwrCapability.html

In order to check if machine is laptop or desktop you can try to check battery status, using SystemPowerCapabilites.LidPresent or both of them.

Battery:

if(SystemInformation.PowerStatus.BatteryChargeStatus ==BatteryChargeStatus.NoSystemBattery){
  //desktop 
}
else{
  //laptop
}

SystemPowerCapabilites.LidPresent:

public SYSTEM_POWER_CAPABILITIES getSystemPowerCapabilites(){
{
    SYSTEM_POWER_CAPABILITIES systemPowerCapabilites;
    GetPwrCapabilities(out systemPowerCapabilites);
    return systemPowerCapabilites;
}

getSystemPowerCapabilites().LidPresent;

GetPwrCapabilities definition: http://www.pinvoke.net/default.aspx/powrprof/GetPwrCapabilities.html

暗地喜欢 2024-07-31 11:01:54

从 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\pcmcia 读取注册表项,“Start”值,如果 start =0 则为笔记本电脑,否则如果 start 不存在或 start != 0 则为台式机。

read registry key from HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\pcmcia, the ‘Start’ value, it's laptop if start =0, otherwise it's desktop machine if start doesn't exist or start != 0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文