Laptop identify thru Code
-
Eurus wrote:
Is it possible to identify if in code if the application is being run in a laptop...?
OK, I'm curious, so before you get flamed to a blackened crisp, I'll bite. Why? :~
0 bottles of beer on the wall, 0 bottles of beer, you take 1 down, pass it around, 4294967295 bottles of beer on the wall. Awasu 2.2.1 [^]: A free RSS/Atom feed reader with support for Code Project.
-
It is possible to see how much of the battery is charged, if it has a battery its probably a laptop.
-
It is possible to see how much of the battery is charged, if it has a battery its probably a laptop.
Though this may not be entirely reliable... (I take my battery out most of the time when I'm running at my desk...)
-
Though this may not be entirely reliable... (I take my battery out most of the time when I'm running at my desk...)
But the battery gauge is still there!
Maxwell Chen
-
I guess you could see what power scheme the OS is set to. regards, Paul Watson Ireland Feed Henry!
eh, stop bugging me about it, give it a couple of days, see what happens.
-
You can use: SYSTEM_POWER_STATUS sps; GetSystemPowerStatus(&sps); if(sps.BatteryFlag==128) { // no battery present } else { // running on a battery } My laptop shows batteryflag = 1 even if I'm running on AC
-
But the battery gauge is still there!
Maxwell Chen
> But the battery gauge is still there! Both my desktop machines at work and at home are running off a UPS, thus by using this approach the code would think the machines are laptops. If it's really worth the effort to you, have a look at the SMBIOS spec. Table 3 contains a byte describing the chassis type. A value of 0x09 means it's a laptop. There are other values that map to similar things, like "notebook" and "sub-notebook", so the interpretation really is still partially up to you...(and no, you can't ask me what the difference is between a laptop and a notebook...or subnotebook). :)
-
> But the battery gauge is still there! Both my desktop machines at work and at home are running off a UPS, thus by using this approach the code would think the machines are laptops. If it's really worth the effort to you, have a look at the SMBIOS spec. Table 3 contains a byte describing the chassis type. A value of 0x09 means it's a laptop. There are other values that map to similar things, like "notebook" and "sub-notebook", so the interpretation really is still partially up to you...(and no, you can't ask me what the difference is between a laptop and a notebook...or subnotebook). :)
Daniel Desormeaux wrote:
Both my desktop machines at work and at home are running off a UPS, thus by using this approach the code would think the machines are laptops.
Not really understand what you mean.
Daniel Desormeaux wrote:
SMBIOS spec. Table 3 contains a byte describing the chassis type. A value of 0x09 means it's a laptop. There are other values that map to similar things, like "notebook" and "sub-notebook",
Did you mean that value of some byte in SMBIOS of a desktop may change when a UPS is attached?
Maxwell Chen
-
You can use: SYSTEM_POWER_STATUS sps; GetSystemPowerStatus(&sps); if(sps.BatteryFlag==128) { // no battery present } else { // running on a battery } My laptop shows batteryflag = 1 even if I'm running on AC
Cabdriver wrote:
My laptop shows batteryflag = 1 even if I'm running on AC
What's the value when the battery is unplugged?
Maxwell Chen
-
Daniel Desormeaux wrote:
Both my desktop machines at work and at home are running off a UPS, thus by using this approach the code would think the machines are laptops.
Not really understand what you mean.
Daniel Desormeaux wrote:
SMBIOS spec. Table 3 contains a byte describing the chassis type. A value of 0x09 means it's a laptop. There are other values that map to similar things, like "notebook" and "sub-notebook",
Did you mean that value of some byte in SMBIOS of a desktop may change when a UPS is attached?
Maxwell Chen
> Did you mean that value of some byte in SMBIOS of a desktop may change when a UPS is attached? I meant the exact opposite of that. :-D I meant that if you look for the presence of a battery, then you will be mislead if you have a UPS hooked up to your desktop (yes, it will report a battery and yes, if you assume anything with a battery is a laptop, it's a bad assumption). And then I suggested that SMBIOS be used because the SMBIOS value doesn't change--eg, it's about the most reliable method (that I know of) to determine whether the machine is a desktop or a laptop. It's too easy to get plain wrong results by looking for a battery through the power management API. -- modified at 11:29 Monday 8th May, 2006 In short: I guess this was the long-winded way to say "looking for a battery is not the correct approach" :-D
-
Cabdriver wrote:
My laptop shows batteryflag = 1 even if I'm running on AC
What's the value when the battery is unplugged?
Maxwell Chen
Sadly the value shows 128 when the battery is removed from the laptop, so that puts a kink in the idea, nevertheless, you could also validate the following registry keys to see if a battery service is installed or if pcmcia was installed: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BattC HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Pcmcia I'm out of the lab at the moment and unable to check if those keys are present on a PC.
-
Sadly the value shows 128 when the battery is removed from the laptop, so that puts a kink in the idea, nevertheless, you could also validate the following registry keys to see if a battery service is installed or if pcmcia was installed: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BattC HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Pcmcia I'm out of the lab at the moment and unable to check if those keys are present on a PC.
Both keys are here on my desktop PC.
-
> But the battery gauge is still there! Both my desktop machines at work and at home are running off a UPS, thus by using this approach the code would think the machines are laptops. If it's really worth the effort to you, have a look at the SMBIOS spec. Table 3 contains a byte describing the chassis type. A value of 0x09 means it's a laptop. There are other values that map to similar things, like "notebook" and "sub-notebook", so the interpretation really is still partially up to you...(and no, you can't ask me what the difference is between a laptop and a notebook...or subnotebook). :)
Yeah, it was just a suggestion, didn't think about an UPS. You are talking about this[^] right? This site[^] has some WMI and C# examples.
ManagementClass management = new ManagementClass("Win32_SystemEnclosure"); ManagementObjectCollection instances = management.GetInstances(); foreach (ManagementObject obj in instances) { ushort[] types = obj.GetPropertyValue("ChassisTypes") as ushort[]; if (types[0] == 9 || types[0] == 10 || types[0] == 14) { Console.WriteLine("This computer is a laptop."); return; } } Console.WriteLine("This computer is a desktop.");
You need to add a reference to System.Management and add a using System.Management; in your code. -
Yeah, it was just a suggestion, didn't think about an UPS. You are talking about this[^] right? This site[^] has some WMI and C# examples.
ManagementClass management = new ManagementClass("Win32_SystemEnclosure"); ManagementObjectCollection instances = management.GetInstances(); foreach (ManagementObject obj in instances) { ushort[] types = obj.GetPropertyValue("ChassisTypes") as ushort[]; if (types[0] == 9 || types[0] == 10 || types[0] == 14) { Console.WriteLine("This computer is a laptop."); return; } } Console.WriteLine("This computer is a desktop.");
You need to add a reference to System.Management and add a using System.Management; in your code.Cool! :-D
Maxwell Chen
-
Yeah, it was just a suggestion, didn't think about an UPS. You are talking about this[^] right? This site[^] has some WMI and C# examples.
ManagementClass management = new ManagementClass("Win32_SystemEnclosure"); ManagementObjectCollection instances = management.GetInstances(); foreach (ManagementObject obj in instances) { ushort[] types = obj.GetPropertyValue("ChassisTypes") as ushort[]; if (types[0] == 9 || types[0] == 10 || types[0] == 14) { Console.WriteLine("This computer is a laptop."); return; } } Console.WriteLine("This computer is a desktop.");
You need to add a reference to System.Management and add a using System.Management; in your code.> You are talking about this[^] right? Yes. > This site[^] has some WMI and C# examples. Looks to me like WMI itself is getting its data through SMBIOS. If you only care about Windows versions that have WMI built in, then that would be the easiest way to get to it.