piglovesrat15 Posted August 23, 2011 Share Posted August 23, 2011 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 More sharing options...
Tripredacus Posted August 23, 2011 Share Posted August 23, 2011 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 More sharing options...
cdob Posted August 23, 2011 Share Posted August 23, 2011 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 foundThis 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 alreadyHowever, I doubt this command describe laptop or desktop always.Testing is required. Link to comment Share on other sites More sharing options...
CoffeeFiend Posted August 24, 2011 Share Posted August 24, 2011 but because of work restrictions, I only allow to use batch files 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 serverThat 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: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.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 aloneSee if running a select query on the Win32_Battery class returns anythingThey 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 More sharing options...
jaclaz Posted August 24, 2011 Share Posted August 24, 2011 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. WMIC SystemEnclosure GET ChassisTypesWMIC ComputerSystem GET PCSystemTypePossibly "PortableBattery" instead of "Battery" is more suited. jaclaz Link to comment Share on other sites More sharing options...
Tripredacus Posted August 24, 2011 Share Posted August 24, 2011 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? Link to comment Share on other sites More sharing options...
jaclaz Posted August 24, 2011 Share Posted August 24, 2011 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? 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 More sharing options...
Tripredacus Posted August 24, 2011 Share Posted August 24, 2011 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? jaclazI 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 More sharing options...
gunsmokingman Posted August 24, 2011 Share Posted August 24, 2011 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 More sharing options...
jaclaz Posted August 24, 2011 Share Posted August 24, 2011 (edited) 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. 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 August 24, 2011 by jaclaz Link to comment Share on other sites More sharing options...
Tripredacus Posted August 24, 2011 Share Posted August 24, 2011 Yep , but I seem not being able to find *any* reference to WinPE in CoffeeFiend's post either. 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/jaclazOf course, I was expanding the topic a little. And I see you caught my typo 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 More sharing options...
CoffeeFiend Posted August 25, 2011 Share Posted August 25, 2011 Possibly "PortableBattery" instead of "Battery" is more suited. 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 More sharing options...
jaclaz Posted August 25, 2011 Share Posted August 25, 2011 [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.jaclaz Link to comment Share on other sites More sharing options...
CoffeeFiend Posted August 25, 2011 Share Posted August 25, 2011 ]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... Link to comment Share on other sites More sharing options...
jaclaz Posted August 25, 2011 Share Posted August 25, 2011 Oops. Must've been a copy/paste error of some kind! One of the great dangers of posting past one's bedtime... 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. jaclaz Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now