Link to home
Start Free TrialLog in
Avatar of Ruttensoft
Ruttensoft

asked on

Check if Notebook or PC?

Hello

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

Thanks
Avatar of ou_dober
ou_dober
Flag of United States of America image

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"
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

ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ruttensoft,

Did you find a solution for you question?

ou_dober