MSFN Forum: Batch Script to detect Laptop - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Batch Script to detect Laptop Rate Topic: -----

#1 User is offline   piglovesrat15 

  • Newbie
  • Group: Members
  • Posts: 16
  • Joined: 21-December 10
  • OS:none specified
  • Country: Country Flag

Posted 23 August 2011 - 08:33 AM

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


#2 User is offline   Tripredacus 

  • K-Mart-ian Legend
  • Group: Super Moderator
  • Posts: 8,689
  • Joined: 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Posted 23 August 2011 - 08:41 AM

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.

#3 User is offline   cdob 

  • Friend of MSFN
  • PipPipPipPipPip
  • Group: Members
  • Posts: 876
  • Joined: 29-September 05

Posted 23 August 2011 - 10:27 AM

View Postpiglovesrat15, on 23 August 2011 - 08:33 AM, said:

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 User is offline   CoffeeFiend 

  • Coffee Aficionado
  • Group: Super Moderator
  • Posts: 5,399
  • Joined: 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 23 August 2011 - 08:25 PM

View Postpiglovesrat15, on 23 August 2011 - 08:33 AM, said:

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

:wacko: That's a pretty strange restriction.

View PostTripredacus, on 23 August 2011 - 08:41 AM, said:

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.

#5 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,454
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 24 August 2011 - 02:18 AM

View PostCoffeeFiend, on 23 August 2011 - 08:25 PM, said:

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 User is offline   Tripredacus 

  • K-Mart-ian Legend
  • Group: Super Moderator
  • Posts: 8,689
  • Joined: 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Posted 24 August 2011 - 08:50 AM

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?

#7 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,454
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 24 August 2011 - 08:58 AM

View PostTripredacus, on 24 August 2011 - 08:50 AM, said:

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:

View Postpiglovesrat15, on 23 August 2011 - 08:33 AM, said:

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 User is offline   Tripredacus 

  • K-Mart-ian Legend
  • Group: Super Moderator
  • Posts: 8,689
  • Joined: 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Posted 24 August 2011 - 11:49 AM

View Postjaclaz, on 24 August 2011 - 08:58 AM, said:

View PostTripredacus, on 24 August 2011 - 08:50 AM, said:

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

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


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

#9 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 24 August 2011 - 12:14 PM

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



#10 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,454
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 24 August 2011 - 12:23 PM

View PostTripredacus, on 24 August 2011 - 11:49 AM, said:

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

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


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

This post has been edited by jaclaz: 24 August 2011 - 12:26 PM


#11 User is offline   Tripredacus 

  • K-Mart-ian Legend
  • Group: Super Moderator
  • Posts: 8,689
  • Joined: 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Posted 24 August 2011 - 01:38 PM

View Postjaclaz, on 24 August 2011 - 12:23 PM, said:

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.

#12 User is offline   CoffeeFiend 

  • Coffee Aficionado
  • Group: Super Moderator
  • Posts: 5,399
  • Joined: 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 25 August 2011 - 12:03 AM

View Postjaclaz, on 24 August 2011 - 02:18 AM, said:

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.

View PostTripredacus, on 24 August 2011 - 08:50 AM, said:

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.

View Postjaclaz, on 24 August 2011 - 02:18 AM, said:

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.

#13 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,454
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 25 August 2011 - 02:12 AM

View PostCoffeeFiend, on 25 August 2011 - 12:03 AM, said:

[

View Postjaclaz, on 24 August 2011 - 02:18 AM, said:

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 User is offline   CoffeeFiend 

  • Coffee Aficionado
  • Group: Super Moderator
  • Posts: 5,399
  • Joined: 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 25 August 2011 - 04:34 AM

View PostTripredacus, on 25 August 2011 - 02:12 AM, said:

View PostCoffeeFiend, on 25 August 2011 - 12:03 AM, said:

]

View PostOscar Wilde, on 24 August 2011 - 02:18 AM, said:

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:

#15 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,454
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 25 August 2011 - 04:52 AM

View PostCoffeeFiend, on 25 August 2011 - 04:34 AM, said:

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

Oscar Wilde said:

A poet can survive everything but a misprint.


Oscar Wilde said:

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 User is offline   rgrant1993 

  • Newbie
  • Group: Members
  • Posts: 12
  • Joined: 20-August 11
  • OS:Windows 7 x86
  • Country: Country Flag

Posted 26 August 2011 - 09:06 AM

just use this:

@echo off
Color 0c
wmic csproduct get name
pause




#17 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,454
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 26 August 2011 - 09:21 AM

View Postrgrant1993, on 26 August 2011 - 09:06 AM, said:

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 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,364
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 26 August 2011 - 10:16 AM

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'


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy