检测应用程序是否在笔记本电脑上运行[重复]

时间:2022-02-15 05:31:25

Possible Duplicate:
How can I tell if a user is using a laptop

可能的重复:如何判断用户是否在使用笔记本电脑

I'm trying to find out if the application is running on a laptop or on a desktop, any ideas on how to achieve this?

我想知道应用程序是在笔记本电脑上运行还是在桌面上运行,有什么想法可以实现吗?

Note: I'm interested only in API's written in Delphi and/or C++.

注意:我只对用Delphi和/或c++编写的API感兴趣。

EDIT: my target platform is Windows XP+, even Windows 7 only is OK.

编辑:我的目标平台是Windows XP+,即使只有Windows 7也可以。

LAST EDIT: thank you all for your help, I have created a unit with helper methods(In Delphi) feel free to translate to C++ or other languages and/or help extending(or fixing possible flaws). The unit can be found here http://www.delphigeist.com/2011/02/laptop-specific-functions.html

最后一次编辑:感谢您的帮助,我创建了一个带有helper方法的单元(在Delphi中),您可以将其转换为c++或其他语言,或者帮助扩展(或修复可能的缺陷)。单位可以在这里找到http://www.delphigeist.com/2011/02/laptop-specific-functions.html

6 个解决方案

#1


16  

Use this struct : SYSTEM_POWER_STATUS, and check the value of ACLineStatus field.

使用这个struct: SYSTEM_POWER_STATUS,并检查ACLineStatus字段的值。

  • ACLineStatus = 0 => The system is not using AC power > Laptop + battery
  • ACLineStatus = 0 =>系统没有使用交流电源>笔记本电脑+电池
  • ACLineStatus = 1 => The system is using AC power => Laptop + AC
  • ACLineStatus = 1 =>系统使用交流电源=>笔记本+ AC
  • ACLineStatus = 255 => AC power status is unknown => Desktop
  • ACLineStatus = 255 =>交流电源状态未知=>桌面。

Disclaimer : Try experimenting with these. I'm not claiming if they're reliable. But they're almost correct.

免责声明:试试这些。我不是在说他们是否可靠。但是他们几乎是正确的。

--

- - -

EDIT:

编辑:

Use GetSystemPowerStatus to get the value of the above mentioned structure.

使用getsyst力气获取上述结构的值。

By the way, you can also experiment with the other fields of the structure; maybe you can find some useful pattern, giving you some combination of values of different fields to help you reliably detect if application is running on laptop or not.

顺便说一下,你也可以对结构的其他领域进行实验;也许您可以找到一些有用的模式,提供一些不同字段值的组合,以帮助您可靠地检测应用程序是否在笔记本上运行。

#2


9  

I don't think there's a standard way to check whether the application runs on a laptop, but I think there's also no standard rationale for needing to know this.

我不认为有一种标准的方法来检查应用程序是否在笔记本上运行,但我认为也没有标准的理由需要知道这一点。

The point is also that a laptop is no so much different from a desktop: there are laptops that get never moved, and I guess it would be possible to build a desktop with an embedded UPS (seen as a battery?)

问题的关键在于,笔记本电脑和桌面电脑并没有太大的不同:有些笔记本电脑永远不会被移动,我猜有可能用嵌入式UPS(被视为电池?)

I think you should find out if it's a laptop using the features you need to check in a laptop:

我认为你应该弄清楚这是否是一台笔记本电脑,使用你需要在笔记本电脑上检查的功能:

  • Do you want to know if it's a laptop because your application needs to behave differently if the computer may be moved around? Then check if it has got a battery plugged in.

    你想知道它是否是笔记本电脑吗?因为如果你的应用程序需要移动电脑,那么它的行为就会有所不同。然后检查它是否插上了电池。

  • Do you want to know if it's a laptop in order to see whether hardware can be modified? In this case check the motherboard model or ask with a dialog box.

    你想知道它是笔记本电脑还是硬件可以修改?在这种情况下,检查主板模型或询问对话框。

  • Do you need to check it in order to know if it will burn to death if used too intensively for too long? Just monitor the temperature...

    你是否需要检查它,以知道它是否会烧到死亡,如果使用太久?监控温度……

#3


4  

I don't believe there is a reliable way to detect this.

我不相信有可靠的方法来检测这个。

#4


3  

Apparently, the hidden problem is that the company laptops typically have not enough memory, but the company desktops do. To address this specific problem, compare memory used against memory installed: EnumProcesses() and GetProcessMemoryInfo tells you the first; GetPhysicallyInstalledSystemMemory() tells you the second.

显然,隐藏的问题是,公司的笔记本电脑通常没有足够的内存,但公司的台式机却有。要解决这个特定的问题,请将使用的内存与安装的内存进行比较:EnumProcesses()和GetProcessMemoryInfo告诉您第一个问题;GetPhysicallyInstalledSystemMemory()告诉您第二个。

If they're too close, you can inform the user that there are 73 running processes using 2.5 GB, but only 2GB RAM is present. This is a valid reason for your program not to start.

如果它们太接近了,您可以通知用户有73个运行进程使用2.5 GB,但是只有2GB RAM存在。这是程序不启动的一个有效理由。

#5


2  

The MSDN discusses API for Power and Device Aware applications here

MSDN讨论了Power和设备感知应用程序的API。

You could also check other things like:

你也可以检查其他东西,比如:

  • Is battery connected
  • 电池连接
  • Is track pad connected
  • 跟踪板连接
  • Is PC Card installed Is
  • 电脑卡是否已安装
  • Has a certain type of CPU (low power, Atom, etc)
  • 具有一定类型的CPU(低功耗、原子等)
  • Has a screen unique to laptop.
  • 拥有笔记本电脑特有的屏幕。
  • laptop hardrive is 3.5"
  • 笔记本电脑hardrive是3.5”

If a certain number of the above is true then you can assume laptop.

如果上面的某些数字是正确的,那么您可以假设是笔记本电脑。

You could also just ask the user at installation....

你也可以问问用户在安装....

#6


1  

Here's a bunch of other answers and links you might find useful for this question:

这里有一些其他的答案和链接,你可能会发现这个问题很有用:

How to detect when the laptop is running on batteries?

如何检测笔记本电脑何时在电池上运行?

How can I tell if a user is using a laptop

如何判断用户是否在使用笔记本电脑

The latter also discusses WMI, while the answer is centred around .NET you can use WMI from Delphi.

后者还讨论了WMI,而答案集中在。net上,您可以使用Delphi中的WMI。

#1


16  

Use this struct : SYSTEM_POWER_STATUS, and check the value of ACLineStatus field.

使用这个struct: SYSTEM_POWER_STATUS,并检查ACLineStatus字段的值。

  • ACLineStatus = 0 => The system is not using AC power > Laptop + battery
  • ACLineStatus = 0 =>系统没有使用交流电源>笔记本电脑+电池
  • ACLineStatus = 1 => The system is using AC power => Laptop + AC
  • ACLineStatus = 1 =>系统使用交流电源=>笔记本+ AC
  • ACLineStatus = 255 => AC power status is unknown => Desktop
  • ACLineStatus = 255 =>交流电源状态未知=>桌面。

Disclaimer : Try experimenting with these. I'm not claiming if they're reliable. But they're almost correct.

免责声明:试试这些。我不是在说他们是否可靠。但是他们几乎是正确的。

--

- - -

EDIT:

编辑:

Use GetSystemPowerStatus to get the value of the above mentioned structure.

使用getsyst力气获取上述结构的值。

By the way, you can also experiment with the other fields of the structure; maybe you can find some useful pattern, giving you some combination of values of different fields to help you reliably detect if application is running on laptop or not.

顺便说一下,你也可以对结构的其他领域进行实验;也许您可以找到一些有用的模式,提供一些不同字段值的组合,以帮助您可靠地检测应用程序是否在笔记本上运行。

#2


9  

I don't think there's a standard way to check whether the application runs on a laptop, but I think there's also no standard rationale for needing to know this.

我不认为有一种标准的方法来检查应用程序是否在笔记本上运行,但我认为也没有标准的理由需要知道这一点。

The point is also that a laptop is no so much different from a desktop: there are laptops that get never moved, and I guess it would be possible to build a desktop with an embedded UPS (seen as a battery?)

问题的关键在于,笔记本电脑和桌面电脑并没有太大的不同:有些笔记本电脑永远不会被移动,我猜有可能用嵌入式UPS(被视为电池?)

I think you should find out if it's a laptop using the features you need to check in a laptop:

我认为你应该弄清楚这是否是一台笔记本电脑,使用你需要在笔记本电脑上检查的功能:

  • Do you want to know if it's a laptop because your application needs to behave differently if the computer may be moved around? Then check if it has got a battery plugged in.

    你想知道它是否是笔记本电脑吗?因为如果你的应用程序需要移动电脑,那么它的行为就会有所不同。然后检查它是否插上了电池。

  • Do you want to know if it's a laptop in order to see whether hardware can be modified? In this case check the motherboard model or ask with a dialog box.

    你想知道它是笔记本电脑还是硬件可以修改?在这种情况下,检查主板模型或询问对话框。

  • Do you need to check it in order to know if it will burn to death if used too intensively for too long? Just monitor the temperature...

    你是否需要检查它,以知道它是否会烧到死亡,如果使用太久?监控温度……

#3


4  

I don't believe there is a reliable way to detect this.

我不相信有可靠的方法来检测这个。

#4


3  

Apparently, the hidden problem is that the company laptops typically have not enough memory, but the company desktops do. To address this specific problem, compare memory used against memory installed: EnumProcesses() and GetProcessMemoryInfo tells you the first; GetPhysicallyInstalledSystemMemory() tells you the second.

显然,隐藏的问题是,公司的笔记本电脑通常没有足够的内存,但公司的台式机却有。要解决这个特定的问题,请将使用的内存与安装的内存进行比较:EnumProcesses()和GetProcessMemoryInfo告诉您第一个问题;GetPhysicallyInstalledSystemMemory()告诉您第二个。

If they're too close, you can inform the user that there are 73 running processes using 2.5 GB, but only 2GB RAM is present. This is a valid reason for your program not to start.

如果它们太接近了,您可以通知用户有73个运行进程使用2.5 GB,但是只有2GB RAM存在。这是程序不启动的一个有效理由。

#5


2  

The MSDN discusses API for Power and Device Aware applications here

MSDN讨论了Power和设备感知应用程序的API。

You could also check other things like:

你也可以检查其他东西,比如:

  • Is battery connected
  • 电池连接
  • Is track pad connected
  • 跟踪板连接
  • Is PC Card installed Is
  • 电脑卡是否已安装
  • Has a certain type of CPU (low power, Atom, etc)
  • 具有一定类型的CPU(低功耗、原子等)
  • Has a screen unique to laptop.
  • 拥有笔记本电脑特有的屏幕。
  • laptop hardrive is 3.5"
  • 笔记本电脑hardrive是3.5”

If a certain number of the above is true then you can assume laptop.

如果上面的某些数字是正确的,那么您可以假设是笔记本电脑。

You could also just ask the user at installation....

你也可以问问用户在安装....

#6


1  

Here's a bunch of other answers and links you might find useful for this question:

这里有一些其他的答案和链接,你可能会发现这个问题很有用:

How to detect when the laptop is running on batteries?

如何检测笔记本电脑何时在电池上运行?

How can I tell if a user is using a laptop

如何判断用户是否在使用笔记本电脑

The latter also discusses WMI, while the answer is centred around .NET you can use WMI from Delphi.

后者还讨论了WMI,而答案集中在。net上,您可以使用Delphi中的WMI。