Free for PREMIUM members
[Webinar] Streamline your web hosting managementRegister Today
Public Function IsLaptop() As Boolean
Dim obj As Object
Dim result as Boolean = False
Set obj = GetObject("winmgmts://./root/cimv2").InstancesOf("Win32_Battery")
For Each battery In obj
result = True
Open in new window
' Example VBScript to check if computer is laptop or workstation
' Author Lance Dobbs
' Version 1.1 - July 2009
If IsLaptop( "." ) Then
WScript.Echo "Desktop or server"
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.
' 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
On Error Resume Next
Set objWMIService = GetObject( "winmgmts://" & myComputer & "/root/cimv2" )
Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery", , 48 )
IsLaptop = False
For Each objItem in colItems
IsLaptop = True
If Err Then Err.Clear
On Error Goto 0
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Premium members get this course for $159.20.
Premium members get this course for $95.20.
Premium members get this course for $39.20.
Premium members get this course for $174.99.
Premium members get this course for $79.20.
Premium members get this course for $151.20.
Premium members get this course for $63.20.