Rob van der Woude's Scripting Pages

VBScript Scripting Techniques > Inventory > Laptop

Check if a computer is a laptop

 

WMI (Win32_Battery)
VBScript Code:
If IsLaptop( "." ) Then
    WScript.Echo "Laptop"
Else
    WScript.Echo "Desktop or server"
End If


Function IsLaptop( myComputer )
' This Function checks if a computer has a battery pack.
' One can assume that a computer with a battery pack is a laptop.
'
' Argument:
' myComputer   [string] name of the computer to check,
'                       or "." for the local computer
' Return value:
' True if a battery is detected, otherwise False
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
    On Error Resume Next
    Set objWMIService = GetObject( "winmgmts://" & myComputer & "/root/cimv2" )
    Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery" )
    IsLaptop = False
    For Each objItem in colItems
        IsLaptop = True
    Next
    If Err Then Err.Clear
    On Error Goto 0
End Function
Requirements:
Windows version: 2000, XP, Server 2003, or Vista (or NT 4 with WMI CORE 1.5)
Network: Stand-alone, workgroup, NT domain, or AD
Client software: WMI CORE 1.5 for Windows NT 4
Script Engine: any
Summarized: Can work in Windows NT 4 or later, but WMI CORE 1.5 is required for Windows NT 4.
Can be used in *.vbs with CSCRIPT.EXE or WSCRIPT.EXE, as well as in HTAs.
Doesn't work in Windows 95, 98 or ME.
 
[Back to the top of this page]

page last modified: 2016-09-19; loaded in 0.0013 seconds