Solved

Check if Notebook or PC?

Posted on 2009-07-03
4
233 Views
Last Modified: 2012-05-07
Hello

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

Thanks
0
Comment
Question by:Ruttensoft
  • 2
4 Comments
 
LVL 6

Expert Comment

by:ou_dober
ID: 24773803
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

0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 24773896
Try with the following vb.net 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

  Next

  Return result

End Function

Open in new window

0
 
LVL 6

Expert Comment

by:ou_dober
ID: 24804072
Ruttensoft,

Did you find a solution for you question?

ou_dober
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now