Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Batch Script to detect Laptop

- - - - -

  • Please log in to reply
17 replies to this topic

#1
piglovesrat15

piglovesrat15

    Newbie

  • Member
  • 30 posts
  • Joined 21-December 10
  • OS:none specified
  • Country: Country Flag
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


How to remove advertisement from MSFN

#2
Tripredacus

Tripredacus

    K-Mart-ian Legend

  • Super Moderator
  • 9,907 posts
  • Joined 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Donator

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.
MSFN RULES | GimageX HTA for PE 3-5 | lol probloms
msfn2_zpsc37c7153.jpg

#3
cdob

cdob

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,000 posts
  • Joined 29-September 05

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.

#4
CoffeeFiend

CoffeeFiend

    Coffee Aficionado

  • Super Moderator
  • 5,399 posts
  • Joined 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

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:
  • 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.
Coffee: \ˈkȯ-fē, ˈkä-\. noun. Heaven in a cup. Life's only treasure. The meaning of life. Kaffee ist wunderbar. C8H10N4O2 FTW.

#5
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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

#6
Tripredacus

Tripredacus

    K-Mart-ian Legend

  • Super Moderator
  • 9,907 posts
  • Joined 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Donator

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?
MSFN RULES | GimageX HTA for PE 3-5 | lol probloms
msfn2_zpsc37c7153.jpg

#7
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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

#8
Tripredacus

Tripredacus

    K-Mart-ian Legend

  • Super Moderator
  • 9,907 posts
  • Joined 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Donator


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.
MSFN RULES | GimageX HTA for PE 3-5 | lol probloms
msfn2_zpsc37c7153.jpg

#9
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,419 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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



GunSmokingMan



#10
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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/fi...isupportscript/

jaclaz

Edited by jaclaz, 24 August 2011 - 12:26 PM.


#11
Tripredacus

Tripredacus

    K-Mart-ian Legend

  • Super Moderator
  • 9,907 posts
  • Joined 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Donator

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/fi...isupportscript/

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.
MSFN RULES | GimageX HTA for PE 3-5 | lol probloms
msfn2_zpsc37c7153.jpg

#12
CoffeeFiend

CoffeeFiend

    Coffee Aficionado

  • Super Moderator
  • 5,399 posts
  • Joined 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

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.
Coffee: \ˈkȯ-fē, ˈkä-\. noun. Heaven in a cup. Life's only treasure. The meaning of life. Kaffee ist wunderbar. C8H10N4O2 FTW.

#13
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

[


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

#14
CoffeeFiend

CoffeeFiend

    Coffee Aficionado

  • Super Moderator
  • 5,399 posts
  • Joined 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag


]


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:


Coffee: \ˈkȯ-fē, ˈkä-\. noun. Heaven in a cup. Life's only treasure. The meaning of life. Kaffee ist wunderbar. C8H10N4O2 FTW.

#15
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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

#16
rgrant1993

rgrant1993

    Newbie

  • Member
  • 12 posts
  • Joined 20-August 11
  • OS:Windows 7 x86
  • Country: Country Flag
just use this:

@echo off
Color 0c
wmic csproduct get name
pause


I'm not fluent in stupid, So please speak slowly and clearly.




#17
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,572 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

just use this:

Perfect! :thumbup
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
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,540 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

As both jaclaz and CoffeeFiend mentioned earlier, if your systems are Windows Vista or newer then:
@(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'





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users