Jump to content

Batch Script to detect Laptop


Recommended Posts

Anyone knows or has a batch script to detect if the computer is a laptop or not? I see many out there with VB script but because of work restrictions, I only allow to use batch files. What I want to accomplish is after the image is applied, user logs on, the script runs once and checks to see if the computer is a laptop or not. If it's a laptop, it will install the encryption software on the laptop.

Thanks in advance

Link to comment
Share on other sites


I detect notebooks via checking the Model (or Manufacturer) in WMI, then compare against a list of supported model numbers in a text file that is on the server. If the model matches up (at this point it doesn't matter if its a notebook or desktop) it runs the appropriate commands for that model.

Link to comment
Share on other sites

Anyone knows or has a batch script to detect if the computer is a laptop or not? I see many out there with VB script but because of work restrictions, I only allow to use batch files. What I want to accomplish is after the image is applied, user logs on, the script runs once and checks to see if the computer is a laptop or not. If it's a laptop, it will install the encryption software on the laptop.

A idea, exptect a battery match a laptop.

reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{72631E54-78A4-11D0-BCF7-00AA00B7B32A}\0000" && echo battery found

This assumes a new installation, not a image restore.

Or if a image is restored: image dosn't contain HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{72631E54-78A4-11D0-BCF7-00AA00B7B32A}\0000 already

However, I doubt this command describe laptop or desktop always.

Testing is required.

Link to comment
Share on other sites

but because of work restrictions, I only allow to use batch files

:wacko: That's a pretty strange restriction.

I detect notebooks via checking the Model (or Manufacturer) in WMI, then compare against a list of supported model numbers in a text file that is on the server

That works if you have a limited range of models in use at any point and also have the manpower to maintain the lists. I'd personally call this more of a "last resort" solution... Especially when there are plenty of standard & effective ways to do exactly what he's asking for.

Anyways. There's 3 fairly standard ways to do this using WMI:

  1. You run a select query on the Win32_SystemEnclosure class, and see if the ChassisTypes property of instances returned (it's not uncommon to have more than one item in it like 8 and 12) is either 9 (Laptop), 10 (Notebook) or 14 (Sub Notebook), and perhaps 12 (Docking Station) too.
  2. The PCSystemType property of the Win32_ComputerSystem class returns 2 (Mobile), but that only works on newer PCs (Vista/7 -- not XP and below) so you can't rely on that alone
  3. See if running a select query on the Win32_Battery class returns anything

They all depend on the vendor's support (properly implementing WMI support) and sometimes driver installation too. So it's a good idea to "combine" these checks together.

It's fairly trivial to do in vbscript, jscript, powershell and several .NET languages like C#. I'll happily provide code for any of these if it helps.

Link to comment
Share on other sites

It's fairly trivial to do in vbscript, jscript, powershell and several .NET languages like C#. I'll happily provide code for any of these if it helps.

And it can be done also in batch through WMIC. :angel

WMIC SystemEnclosure GET ChassisTypes

WMIC ComputerSystem GET PCSystemType

Possibly "PortableBattery" instead of "Battery" is more suited. :unsure:

jaclaz

Link to comment
Share on other sites

Will WMI still detect a battery if it is not present in the system? We do not put batteries in until much later.

Also, do you expect that WMI can find a battery from a WinPE?

WHICH WinPE? :w00t:

What I want to accomplish is after the image is applied, user logs on, the script runs once and checks to see if the computer is a laptop or not. If it's a laptop, it will install the encryption software on the laptop.

jaclaz

Link to comment
Share on other sites

Will WMI still detect a battery if it is not present in the system? We do not put batteries in until much later.

Also, do you expect that WMI can find a battery from a WinPE?

WHICH WinPE? :w00t:

jaclaz

I wasn't specifically referring to the OP, but to

That works if you have a limited range of models in use at any point and also have the manpower to maintain the lists. I'd personally call this more of a "last resort" solution... Especially when there are plenty of standard & effective ways to do exactly what he's asking for.

As for WinPE, I'm thinking Win PE 3.0 x64.

Link to comment
Share on other sites

Here a script using WMI Win32_SystemEnclosure with a list of retuen values


Dim Wmi :Set Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Dim Arg, Col, Obj

For Each Col In Wmi.ExecQuery("Select * from Win32_SystemEnclosure")
For Each Obj In Col.ChassisTypes
Select Case Obj
Case 1 :Arg = "Other"
Case 2 :Arg = "Unknown"
Case 3 :Arg = "Desktop"
Case 4 :Arg = "Low Profile Desktop"
Case 5 :Arg = "Pizza Box"
Case 6 :Arg = "Mini Tower"
Case 7 :Arg = "Tower"
Case 8 :Arg = "Portable"
Case 9 :Arg = "Laptop"
Case 10 :Arg = "Notebook"
Case 11 :Arg = "Handheld"
Case 12 :Arg = "Docking Station"
Case 13 :Arg = "All-in-One"
Case 14 :Arg = "Sub-Notebook"
Case 15 :Arg = "Space Saving"
Case 16 :Arg = "Lunch Box"
Case 17 :Arg = "Main System Chassis"
Case 18 :Arg = "Expansion Chassis"
Case 19 :Arg = "Sub-Chassis"
Case 20 :Arg = "Bus Expansion Chassis"
Case 21 :Arg = "Peripheral Chassis"
Case 22 :Arg = "Storage Chassis"
Case 23 :Arg = "Rack Mount Chassis"
Case 24 :Arg = "Sealed-Case PC"
Case Else
Arg = "Unknown"
End Select
Next
Next

WScript.Echo " Type = " & Arg

Link to comment
Share on other sites

I wasn't specifically referring to the OP, but to

That works if you have a limited range of models in use at any point and also have the manpower to maintain the lists. I'd personally call this more of a "last resort" solution... Especially when there are plenty of standard & effective ways to do exactly what he's asking for.

As for WinPE, I'm thinking Win PE 3.0 x64.

Yep :), but I seem not being able to find *any* reference to WinPE in CoffeeFiend's post either. :unsure:

BTW, and JFYI, WIM support was added very recently (today ;)) to Win7PE, so it is fairly possible to add to WinPE as well, though cannot say about x64:

http://reboot.pro/9246/

http://reboot.pro/files/file/39-wmisupportscript/

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

Yep :), but I seem not being able to find *any* reference to WinPE in CoffeeFiend's post either. :unsure:

BTW, and JFYI, WIM support was added very recently (today ;)) to Win7PE, so it is fairly possible to add to WinPE as well, though cannot say about x64:

http://reboot.pro/9246/

http://reboot.pro/files/file/39-wmisupportscript/

jaclaz

Of course, I was expanding the topic a little. And I see you caught my typo :ph34r:

IDK about that post on reboot.pro... I already ready from WMI in WinPE, but didn't know if it knew what a battery was. I'll have to test some to see if I can get some of the values that GSM posted.

Link to comment
Share on other sites

Possibly "PortableBattery" instead of "Battery" is more suited. :unsure:

I do know Win32_Battery definitely works. I'll have to try Win32_PortableBattery sometime. But when one doesn't work the other most likely doesn't either (like if the device isn't detected or such). But either ways it's ridiculously simple to add that extra check.

Will WMI still detect a battery if it is not present in the system? We do not put batteries in until much later.

I can't say I've ever tried that. Nor did I try before chipset drivers are installed (it might not be detected yet, maybe). You'd have to try to see.

Also, do you expect that WMI can find a battery from a WinPE?

I never boot in WinPE so I can't say for sure.

Either ways, batteries may not be detected in some situations. But the other 2 classes get their infos from SMBIOS tables which works regardless of drivers. So long as the tables were filled properly by the OEM of course (that's not so much a problem today as it was in the Win2k era). I personally wouldn't rely on the battery check(s) alone.

Link to comment
Share on other sites

]

Also, do you expect that WMI can find a battery from a WinPE?

I never boot in WinPE so I can't say for sure.

Please note how that question was posted by Tripredacus and NOT by me.

Oops. Must've been a copy/paste error of some kind! One of the great dangers of posting past one's bedtime...

:whistle:

Link to comment
Share on other sites

Oops. Must've been a copy/paste error of some kind! One of the great dangers of posting past one's bedtime...

:whistle:

Yep :), a couple real ones ;):

A poet can survive everything but a misprint.

I always pass on good advice. It is the only thing to do with it. It is never of any use to oneself.

:lol:

jaclaz

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...