Detect if application is running on laptop [duplicate]
The community reviewed whether to reopen this question 11 months ago and left it closed:
Original close reason(s) were not resolved
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++.
EDIT: my开发者_StackOverflow中文版 target platform is Windows XP+, even Windows 7 only is OK.
Use this struct : SYSTEM_POWER_STATUS
, and check the value of ACLineStatus
field.
- ACLineStatus = 0 => The system is not using AC power > Laptop + battery
- ACLineStatus = 1 => The system is using AC power => Laptop + AC
- ACLineStatus = 255 => AC power status is unknown => Desktop
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.
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.
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?)
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...
I don't believe there is a reliable way to detect this.
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.
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.
The MSDN discusses API for Power and Device Aware applications here
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)
- Has a screen unique to laptop.
- laptop hardrive is 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....
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.
精彩评论