Batch Script to detect Laptop
#1
Posted 23 August 2011 - 08:33 AM
Thanks in advance
#2
Posted 23 August 2011 - 08:41 AM
#3
Posted 23 August 2011 - 10:27 AM
piglovesrat15, on 23 August 2011 - 08:33 AM, said:
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.
#4
Posted 23 August 2011 - 08:25 PM
piglovesrat15, on 23 August 2011 - 08:33 AM, said:
Tripredacus, on 23 August 2011 - 08:41 AM, said:
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:
- 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 alone
- 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.
#5
Posted 24 August 2011 - 02:18 AM
CoffeeFiend, on 23 August 2011 - 08:25 PM, said:
And it can be done also in batch through WMIC.
WMIC SystemEnclosure GET ChassisTypes
WMIC ComputerSystem GET PCSystemType
Possibly "PortableBattery" instead of "Battery" is more suited.
jaclaz
#6
Posted 24 August 2011 - 08:50 AM
Also, do you expect that WMI can find a battery from a WinPE?
#7
Posted 24 August 2011 - 08:58 AM
Tripredacus, on 24 August 2011 - 08:50 AM, said:
Also, do you expect that WMI can find a battery from a WinPE?
WHICH WinPE?
piglovesrat15, on 23 August 2011 - 08:33 AM, said:
jaclaz
#8
Posted 24 August 2011 - 11:49 AM
jaclaz, on 24 August 2011 - 08:58 AM, said:
I wasn't specifically referring to the OP, but to
CoffeeFriend said:
As for WinPE, I'm thinking Win PE 3.0 x64.
#9
Posted 24 August 2011 - 12:14 PM
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
#10
Posted 24 August 2011 - 12:23 PM
Tripredacus, on 24 August 2011 - 11:49 AM, said:
CoffeeFriend said:
As for WinPE, I'm thinking Win PE 3.0 x64.
Yep
BTW, and JFYI, WIM support was added very recently (today
http://reboot.pro/9246/
http://reboot.pro/fi...isupportscript/
jaclaz
This post has been edited by jaclaz: 24 August 2011 - 12:26 PM
#11
Posted 24 August 2011 - 01:38 PM
jaclaz, on 24 August 2011 - 12:23 PM, said:
BTW, and JFYI, WIM support was added very recently (today
http://reboot.pro/9246/
http://reboot.pro/fi...isupportscript/
jaclaz
Of 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.
#12
Posted 25 August 2011 - 12:03 AM
jaclaz, on 24 August 2011 - 02:18 AM, said:
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.
Tripredacus, on 24 August 2011 - 08:50 AM, said:
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.
jaclaz, on 24 August 2011 - 02:18 AM, said:
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.
#13
Posted 25 August 2011 - 02:12 AM
#14
#15
Posted 25 August 2011 - 04:52 AM
CoffeeFiend, on 25 August 2011 - 04:34 AM, said:
Yep
Oscar Wilde said:
Oscar Wilde said:
jaclaz
#16
Posted 26 August 2011 - 09:06 AM
@echo off Color 0c wmic csproduct get name pause
#17
Posted 26 August 2011 - 09:21 AM
rgrant1993, on 26 August 2011 - 09:06 AM, said:
Perfect!
Too bad that it will tell you (maybe ) the actual manufacturer name or maybe nothing, definitely won't tell you whether it is portable or not, so you will have (if a value is returned) to use a database of some kind, to see if the particular model returned is a laptop/netbook or a desktop.
jaclaz
#18
Posted 26 August 2011 - 10:16 AM
@(wmic computersystem get pcsystemtype|find "2">nul 2>&1)&&@(call [encryption stuff])
Using the other WMI class mentioned by jaclaz and used earlier by gunsmokingman:
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
(SET _=)
FOR /F "DELIMS={}" %%# IN (
'2^>NUL WMIC SystemEnclosure GET ChassisTypes^|FIND "}"') DO (
FOR %%$ IN (8 9 10 11 12 14 18 21) DO IF %%#==%%$ SET "_=T")
IF NOT DEFINED _ GOTO :EOF
REM [Encryption stuff here]
ECHO=This is a line of text only visible to a 'portable'
- ← How do i do this? ADVANCED!
- Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
- How do i make a batch file retrieve its location? →



Help
Back to top











