VBScript Scripting Techniques > Inventory > Laptop
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" )
IsLaptop = False
For Each objItem in colItems
IsLaptop = True
If Err Then Err.Clear
On Error Goto 0
|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|
|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 uploaded: 2016-09-19, 14:58|