b l o g

check host if laptop

by admin on Jan.22, 2010, under Workstation

Scenario:

We have a script which needs to be deployed to hosts across the domain footprint which needs to install a small application upon meeting certain criteria.  This seems to be a relatively easy task and can be easily accomplished in several ways. (example) One would be inclined to write a vbscript, use wmi, and enumerate some type of computer/vendor/model attribute prior to the install. To perhaps save some time, here is what we did and below is the criteria we used to make the decision through automation.

Criteria:

  1. The remote host must be online at the time the script is run.
  2. To return the neccessary value (laptop found) the host must be online and have some type of battery as a power source.  In this scenario, we are going to rely on win32_battery to provide us with the necessary results.
  3. Upon detection, install symantec scrip to allow users to update their definitions.
  4. Here is the functon we used to determine whether or not the remote host is a laptop w/ a battery.
Function IsLaptop( myComputer )
    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

Accessing the above Function:

Here is one way you can call upon the code(function) and return the results for later use.

If IsLaptop( "." ) Then
    WScript.Echo "Laptop"
Else
    WScript.Echo "Desktop or server"
End If
:, , ,

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...

Archives

All entries, chronologically...