Check if Notebook or PC?


How can I check in VB.NET if it is a PC or a Notebook?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Here you go.  If you need an action, add it below the echo for if/else.

Hope this helps.
' Shutdown.vbs
' Example VBScript to check if computer is laptop or workstation
' Author Lance Dobbs
' Version 1.1 - July 2009
' --------------------------------------
If IsLaptop( "." ) Then
    WScript.Echo "Laptop"
    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
    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
    If Err Then Err.Clear
    On Error Goto 0
End Function 

Open in new window

Jaime OlivaresSoftware ArchitectCommented:
Try with the following version:

Public Function IsLaptop() As Boolean
     Dim obj As Object
     Dim result as Boolean = False
  Set obj = GetObject("winmgmts://./root/cimv2").InstancesOf("Win32_Battery")
  For Each battery In obj
      result = True
  Return result
End Function

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

Did you find a solution for you question?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.