Improve company productivity with a Business Account.Sign Up
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
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
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.