(view source code of islaptop.vbs as plain text)
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", , 48 )
IsLaptop = False
For Each objItem in colItems
IsLaptop = True
Next
If Err Then Err.Clear
On Error Goto 0
End Function
page last modified: 2024-04-16; loaded in 0.0076 seconds