Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 758
  • Last Modified:

VB Script to check a certain computer name to see if it's a laptop or a PC

I'm looking for a VB Script to check a certain computer name to see if it's a laptop or a pc.

Thanks for your help.
0
smurteira
Asked:
smurteira
  • 2
2 Solutions
 
sirbountyCommented:
Try this:
ref: http://www.robvanderwoude.com/vbstech_inventory_laptop.html
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

Open in new window

0
 
smurteiraAuthor Commented:
It works but you have to come into the script and change the computer name everytime you need to check a computer.  So i tweaked it to have an InPut Box come up and ask me for the computer name.  Here's the final result.  Works like a charm, thanks for your help.

on error resume next
strComputer=InputBox ("Enter the computer name")
Set objWMIservice = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

If IsLaptop( mycomputer ) 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
'
    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
0
 
smurteiraAuthor Commented:
accept
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now