Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Laptop identify thru Code

Laptop identify thru Code

Scheduled Pinned Locked Moved The Lounge
question
16 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Anish M

    Is it possible to identify if in code if the application is being run in a laptop...?

    T Offline
    T Offline
    Taka Muraoka
    wrote on last edited by
    #2

    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.

    1 Reply Last reply
    0
    • A Anish M

      Is it possible to identify if in code if the application is being run in a laptop...?

      S Offline
      S Offline
      Steve Hansen
      wrote on last edited by
      #3

      It is possible to see how much of the battery is charged, if it has a battery its probably a laptop.

      S 1 Reply Last reply
      0
      • S Steve Hansen

        It is possible to see how much of the battery is charged, if it has a battery its probably a laptop.

        S Offline
        S Offline
        steve_hocking
        wrote on last edited by
        #4

        Though this may not be entirely reliable... (I take my battery out most of the time when I'm running at my desk...)

        M 1 Reply Last reply
        0
        • S steve_hocking

          Though this may not be entirely reliable... (I take my battery out most of the time when I'm running at my desk...)

          M Offline
          M Offline
          Maxwell Chen
          wrote on last edited by
          #5

          But the battery gauge is still there!


          Maxwell Chen

          D 1 Reply Last reply
          0
          • A Anish M

            Is it possible to identify if in code if the application is being run in a laptop...?

            P Offline
            P Offline
            Paul Watson
            wrote on last edited by
            #6

            I guess you could see what power scheme the OS is set to. regards, Paul Watson Ireland Feed Henry!

            Shog9 wrote:

            eh, stop bugging me about it, give it a couple of days, see what happens.

            1 Reply Last reply
            0
            • A Anish M

              Is it possible to identify if in code if the application is being run in a laptop...?

              R Offline
              R Offline
              RichardBrock
              wrote on last edited by
              #7

              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

              M 1 Reply Last reply
              0
              • M Maxwell Chen

                But the battery gauge is still there!


                Maxwell Chen

                D Offline
                D Offline
                dandy72
                wrote on last edited by
                #8

                > 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). :)

                M S 2 Replies Last reply
                0
                • D dandy72

                  > 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). :)

                  M Offline
                  M Offline
                  Maxwell Chen
                  wrote on last edited by
                  #9

                  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

                  D 1 Reply Last reply
                  0
                  • R RichardBrock

                    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

                    M Offline
                    M Offline
                    Maxwell Chen
                    wrote on last edited by
                    #10

                    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

                    R 1 Reply Last reply
                    0
                    • M 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

                      D Offline
                      D Offline
                      dandy72
                      wrote on last edited by
                      #11

                      > 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

                      1 Reply Last reply
                      0
                      • M Maxwell Chen

                        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

                        R Offline
                        R Offline
                        RichardBrock
                        wrote on last edited by
                        #12

                        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.

                        S 1 Reply Last reply
                        0
                        • R RichardBrock

                          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.

                          S Offline
                          S Offline
                          Steve Hansen
                          wrote on last edited by
                          #13

                          Both keys are here on my desktop PC.

                          1 Reply Last reply
                          0
                          • D dandy72

                            > 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). :)

                            S Offline
                            S Offline
                            Steve Hansen
                            wrote on last edited by
                            #14

                            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.

                            M D 2 Replies Last reply
                            0
                            • S Steve Hansen

                              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.

                              M Offline
                              M Offline
                              Maxwell Chen
                              wrote on last edited by
                              #15

                              Cool! :-D


                              Maxwell Chen

                              1 Reply Last reply
                              0
                              • S Steve Hansen

                                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.

                                D Offline
                                D Offline
                                dandy72
                                wrote on last edited by
                                #16

                                > 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.

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups