Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for islaptop.vbs

(view source code of islaptop.vbs as plain text)

  1. If IsLaptop( "." ) Then
  2. 	WScript.Echo "Laptop"
  3. Else
  4. 	WScript.Echo "Desktop or server"
  5. End If
  6.  
  7.  
  8. Function IsLaptop( myComputer )
  9. ' This Function checks if a computer has a battery pack.
  10. ' One can assume that a computer with a battery pack is a laptop.
  11. '
  12. ' Argument:
  13. ' myComputer   [string] name of the computer to check,
  14. '                       or "." for the local computer
  15. ' Return value:
  16. ' True if a battery is detected, otherwise False
  17. '
  18. ' Written by Rob van der Woude
  19. ' http://www.robvanderwoude.com
  20. 	On Error Resume Next
  21. 	Set objWMIService = GetObject( "winmgmts://" & myComputer & "/root/cimv2" )
  22. 	Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery", , 48 )
  23. 	IsLaptop = False
  24. 	For Each objItem in colItems
  25. 		IsLaptop = True
  26. 	Next
  27. 	If Err Then Err.Clear
  28. 	On Error Goto 0
  29. End Function
  30.  

page last modified: 2024-04-16; loaded in 0.0098 seconds