Foros del Web » Programación para mayores de 30 ;) » .NET »

Obtener nombre Monitor PC

Estas en el tema de Obtener nombre Monitor PC en el foro de .NET en Foros del Web. Estimados queria consultar si alguien ha podido obtener el nombre de monitor de una pc con .net , no se de que manera podria yo ...
  #1 (permalink)  
Antiguo 30/12/2009, 11:20
 
Fecha de Ingreso: marzo-2008
Mensajes: 37
Antigüedad: 16 años, 1 mes
Puntos: 0
Obtener nombre Monitor PC

Estimados queria consultar si alguien ha podido obtener el nombre de monitor de una pc con .net , no se de que manera podria yo acceder y obtener el nombre del monitor de la pc

He visto las apis de win32 pero sin mayores resultados.

Si alguien me podria ayudar seria grandioso
  #2 (permalink)  
Antiguo 30/12/2009, 20:57
Avatar de seba123neo  
Fecha de Ingreso: febrero-2007
Ubicación: Esperanza, Santa Fe
Mensajes: 1.046
Antigüedad: 17 años, 2 meses
Puntos: 19
Respuesta: Obtener nombre Monitor PC

Hola, creo que con WMI en .NET podes hacerlo...

saludos.
__________________
" Todos Somos Ignorantes; lo que pasa es que no todos ignoramos las mismas cosas " - Albert Einstein
  #3 (permalink)  
Antiguo 31/12/2009, 11:45
 
Fecha de Ingreso: marzo-2008
Mensajes: 37
Antigüedad: 16 años, 1 mes
Puntos: 0
Respuesta: Obtener nombre Monitor PC

Hola Gracias por la pronta respuesta, bueno si lo he intentado con .net pero no muestra el nombre del monitor lo unico que muestra es monitor plug and play mas no el nombre de la marca. Alguna otra forma de poder realizarlo? alguna api tal vez?

Gracias
  #4 (permalink)  
Antiguo 31/12/2009, 17:57
Avatar de seba123neo  
Fecha de Ingreso: febrero-2007
Ubicación: Esperanza, Santa Fe
Mensajes: 1.046
Antigüedad: 17 años, 2 meses
Puntos: 19
Respuesta: Obtener nombre Monitor PC

con la api EnumDisplayDevices se puede obtener la marca del monitor.

Código vb:
Ver original
  1. Const CCDEVICENAME As Short = 32
  2.  
  3.     Private Structure DISPLAY_DEVICE
  4.         Dim cb As Integer
  5.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCDEVICENAME)> _
  6.         Dim DeviceName As String
  7.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
  8.         Dim DeviceString As String
  9.         Dim StateFlags As Short
  10.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
  11.         Dim DeviceID As String
  12.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
  13.         Dim DeviceKey As String
  14.     End Structure
  15.  
  16.     <DllImport("user32.dll")> _
  17.     Private Shared Function EnumDisplayDevices(ByVal Unused As Integer, ByVal iDevNum As Short, ByRef lpDisplayDevice As DISPLAY_DEVICE, ByVal dwFlags As Integer) As Integer
  18.     End Function

DeviceString es la que tiene el nombre del monitor y marca.

saludos.
__________________
" Todos Somos Ignorantes; lo que pasa es que no todos ignoramos las mismas cosas " - Albert Einstein
  #5 (permalink)  
Antiguo 15/01/2010, 19:58
 
Fecha de Ingreso: marzo-2008
Mensajes: 37
Antigüedad: 16 años, 1 mes
Puntos: 0
Respuesta: Obtener nombre Monitor PC

Hola seba123neo gracias por la info como puedo usar esta cllase? cuando copio el codigo que pusiste me sale error tengo que realizar algun import a la clase? me podrias dar una mano porfa

Gracias
  #6 (permalink)  
Antiguo 16/01/2010, 20:11
Avatar de seba123neo  
Fecha de Ingreso: febrero-2007
Ubicación: Esperanza, Santa Fe
Mensajes: 1.046
Antigüedad: 17 años, 2 meses
Puntos: 19
Respuesta: Obtener nombre Monitor PC

si obvio tenes que importar, yo solo te puse la estructura y la API que se usa para hacer lo que queres, pero antes tenes que importar asi:

Código vb:
Ver original
  1. Imports System.Runtime.InteropServices

mira te pongo un ejemplo sin la api , esta con WMI, a mi me funca barbaro, fijate si te anda.

Código vb:
Ver original
  1. Imports System.Management
  2.  
  3. Public Class Form1
  4.  
  5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.         Dim Buscar As New ManagementObjectSearcher("SELECT * FROM Win32_DesktopMonitor")
  7.  
  8.         For Each queryObj As ManagementObject In Buscar.Get()
  9.             MsgBox("La Marca y Modelo de tu Monitor es '" & queryObj("Caption") & "'")
  10.             MsgBox("El Fabricante del Monitor es '" & queryObj("MonitorManufacturer") & "'")
  11.         Next
  12.     End Sub
  13. End Class

antes agrega la referencia a System.Managament

saludos.
__________________
" Todos Somos Ignorantes; lo que pasa es que no todos ignoramos las mismas cosas " - Albert Einstein
  #7 (permalink)  
Antiguo 19/01/2010, 15:57
 
Fecha de Ingreso: marzo-2008
Mensajes: 37
Antigüedad: 16 años, 1 mes
Puntos: 0
Respuesta: Obtener nombre Monitor PC

HOla seba123neo
Mira estuve probando la Api EnumDisplayDevice , pero en la messagebox cuando deberia mostrar el tipo de monitor no me muestra nada no se que estare haciendo mal a ver si puedes dar una mano

Pego el codigo del formulario

Código:

Option Explicit On
Imports System.Runtime.InteropServices
Public Class Form1

    'for listview column auto-resizing
    Private Const LVM_FIRST As Long = &H1000
    Private Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30)
    Private Const LVSCW_AUTOSIZE As Long = -1
    Private Const LVSCW_AUTOSIZE_USEHEADER As Long = -2

    Const CCDEVICENAME As Short = 32

    Private Declare Function SendMessage Lib "user32" _
       Alias "SendMessageA" _
      (ByVal hwnd As Long, _
       ByVal wMsg As Long, _
       ByVal wParam As Long, _
    ByVal lParam As Long) As Long

    'EnumDisplayDevices Requirements
    '  Windows NT/2000/XP: Included in Windows 2000 and later.
    '  Windows 95/98/Me:   Included in Windows 98 and later.
    Private Structure DISPLAY_DEVICE
        Dim cb As Integer
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCDEVICENAME)> _
        Dim DeviceName As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
        Dim DeviceString As String
        Dim StateFlags As Short
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
        Dim DeviceID As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
        Dim DeviceKey As String
    End Structure

    Private Const DD_ATTACHED_TO_DESKTOP As Long = &H1
    Private Const DD_MULTI_DRIVER As Long = &H2
    Private Const DD_PRIMARY_DEVICE As Long = &H4
    Private Const DD_MIRRORING_DRIVER As Long = &H8
    Private Const DD_VGA_COMPATIBLE As Long = &H10
    Private Const DD_REMOVABLE As Long = &H20
    Private Const DD_DISCONNECT As Long = &H2000000 'WINVER >= 5
    Private Const DD_REMOTE As Long = &H4000000 'WINVER >= 5
    Private Const DD_MODESPRUNED As Long = &H8000000 'WINVER >= 5



   




    Private Sub Form_Load()

        With ListView1
            '.ListItems.Clear()
            '.View = lvwReport
            '.Sorted = False
            '.ColumnHeaders.Clear()
            '.ColumnHeaders.Add, , "DisplayDevice Member"

            ' .ListItems.Add, , "Device Name"
            ' .ListItems.Add, , "Device String"
            ' .ListItems.Add, , "Device StateFlags:"
            '.ListItems.Add, , "  - part of desktop"
            ' .ListItems.Add, , "  - primary device"
            '.ListItems.Add, , "  - pseudo device"
            '.ListItems.Add, , "  - VGA compatible"
            '.ListItems.Add, , "  - removable (cannot be primary)"
            '.ListItems.Add, , "  - more modes than output device"
            '.ListItems.Add, , "Assoc Monitor Name"
            '.ListItems.Add, , "Assoc Monitor String"
            '.ListItems.Add, , "Assoc Monitor StateFlags:"
            '.ListItems.Add, , "  - multi-driver"

        End With

        'Command1.Caption = "EnumDisplayDevices"

        Call EnumSystemDisplayDevices()

    End Sub


    Private Sub Command1_Click()

        Call EnumSystemDisplayDevices()
        Call lvAutosizeControl(ListView1)

    End Sub


    Private Sub EnumSystemDisplayDevices()

        Dim iDevNum As Long
        Dim thiscol As Long
        Dim sDeviceName As String 'required in 3 places
        Dim dev As DISPLAY_DEVICE

        'Query all display devices in the system by
        'calling EnumDisplayDevices in a loop, starting
        'with iDevNum set to 0, and incrementing until
        'the function fails (call returns non-zero if
        'true or 0 if false).

        dev.cb = Len(dev)
        iDevNum = 0
        Dim it As New Convert_Example.MyConvertExampleClass

        Do While EnumDisplayDevices(0&, iDevNum, dev, 0&)

            'for each display device returned,
            'add a new column to the listview
            'and populate its data
            With ListView1

                sDeviceName = TrimNull(it.convierte(dev.DeviceName))

                ' .ColumnHeaders.Add, , sDeviceName
                ' thiscol = (.ColumnHeaders.Count - 1)

                '.ListItems(1).SubItems(thiscol) = sDeviceName
                '.ListItems(2).SubItems(thiscol) = TrimNull(StrConv(dev.DeviceString, vbUnicode))
                '.ListItems(3).SubItems(thiscol) = dev.StateFlags

                If dev.StateFlags And DD_ATTACHED_TO_DESKTOP Then
                    '.ListItems(4).SubItems(thiscol) = "Yes"
                End If

                If dev.StateFlags And DD_PRIMARY_DEVICE Then
                    '.ListItems(5).SubItems(thiscol) = "Yes"
                End If

                If dev.StateFlags And DD_MIRRORING_DRIVER Then
                    '.ListItems(6).SubItems(thiscol) = "Yes"
                End If

                If dev.StateFlags And DD_VGA_COMPATIBLE Then
                    ' .ListItems(7).SubItems(thiscol) = "Yes"
                End If

                If dev.StateFlags And DD_REMOVABLE Then
                    '.ListItems(8).SubItems(thiscol) = "Yes"
                End If

                If dev.StateFlags And DD_MODESPRUNED Then
                    '.ListItems(9).SubItems(thiscol) = "Yes"
                End If

                'When null was passed as lpDevice above,
                'information about the display device (adapter)
                'was returned. By calling the API once again,
                'this time specifying lpDevice=dev.devicename and
                'iDevNum=0, the same call returns information about
                'the monitor connected to the specified device.
                If EnumDisplayDevices(sDeviceName, 0, dev, 0&) <> 0 Then
                    '.ListItems(10).SubItems(thiscol) = TrimNull(StrConv(dev.DeviceName, vbUnicode))
                    '.ListItems(11).SubItems(thiscol) = TrimNull(StrConv(dev.DeviceString, vbUnicode))
                    '.ListItems(12).SubItems(thiscol) = dev.StateFlags
                    MessageBox.Show("Moni es " & dev.DeviceString)

                    If dev.StateFlags And DD_MULTI_DRIVER Then
                        '.ListItems(13).SubItems(thiscol) = "Yes"
                    End If

                End If

            End With

            iDevNum = iDevNum + 1

        Loop

    End Sub


    Private Sub lvAutosizeControl(ByVal lv As ListView)

        Dim col2adjust As Long

        'Size each column based on the maximum of
        'either the ColumnHeader text width, or,
        'if the items below it are wider, the
        'widest list item in the column

        lv.Visible = False
        'For col2adjust = 0 To lv.ColumnHeaders.Count - 1

        'Call SendMessage(lv.hwnd, _
        '  LVM_SETCOLUMNWIDTH, _
        '  col2adjust, _
        '   ByVal LVSCW_AUTOSIZE_USEHEADER)

        'Next
        lv.Visible = True

    End Sub


    Private Function TrimNull(ByVal item As String)

        Dim pos As Integer

        'double check that there is a chr$(0) in the string
        'pos = InStr(item, Chr$(0))
        If pos Then
            'TrimNull = Left$(item, pos - 1)
        Else
            'TrimNull = item
        End If


    End Function
    <DllImport("user32.dll")> _
    Private Shared Function EnumDisplayDevices(ByVal Unused As Integer, ByVal iDevNum As Short, ByRef lpDisplayDevice As DISPLAY_DEVICE, ByVal dwFlags As Integer) As Integer
    End Function


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call EnumSystemDisplayDevices()
    End Sub
End Class






Respecto al WMi yo lo probe pero me sale Tipo de monitor estandar no me sale la marca
  #8 (permalink)  
Antiguo 20/01/2010, 21:29
Avatar de seba123neo  
Fecha de Ingreso: febrero-2007
Ubicación: Esperanza, Santa Fe
Mensajes: 1.046
Antigüedad: 17 años, 2 meses
Puntos: 19
Respuesta: Obtener nombre Monitor PC

si, el ejemplo ese que pusiste es de visual basic 6, de esta pagina:

EnumDisplayDevices: Enumerating System Display Devices

y el ejemplo de WMI es raro que no te ande, a mi me tira la marca tal cual es. ahora le puse mas propiedades de la clase , fijate si con esto te tira en alguna la marca del monitor...pone un listbox y este codigo:

Código vb:
Ver original
  1. Imports System.Management
  2.  
  3. Public Class Form1
  4.  
  5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.         Dim Buscar As New ManagementObjectSearcher("SELECT * FROM Win32_DesktopMonitor")
  7.  
  8.         For Each queryObj As ManagementObject In Buscar.Get()
  9.             ListBox1.Items.Add(queryObj("Availability"))
  10.             ListBox1.Items.Add(queryObj("Caption"))
  11.             ListBox1.Items.Add(queryObj("ConfigManagerErrorCode"))
  12.             ListBox1.Items.Add(queryObj("ConfigManagerUserConfig"))
  13.             ListBox1.Items.Add(queryObj("CreationClassName"))
  14.             ListBox1.Items.Add(queryObj("Description"))
  15.             ListBox1.Items.Add(queryObj("DeviceID"))
  16.             ListBox1.Items.Add(queryObj("MonitorManufacturer"))
  17.             ListBox1.Items.Add(queryObj("MonitorType"))
  18.             ListBox1.Items.Add(queryObj("Name"))
  19.             ListBox1.Items.Add(queryObj("PixelsPerXLogicalInch"))
  20.             ListBox1.Items.Add(queryObj("PixelsPerYLogicalInch"))
  21.             ListBox1.Items.Add(queryObj("PNPDeviceID"))
  22.             ListBox1.Items.Add(queryObj("ScreenHeight"))
  23.             ListBox1.Items.Add(queryObj("ScreenWidth"))
  24.             ListBox1.Items.Add(queryObj("Status"))
  25.             ListBox1.Items.Add(queryObj("SystemName"))
  26.         Next
  27.     End Sub
  28. End Class

saludos.
__________________
" Todos Somos Ignorantes; lo que pasa es que no todos ignoramos las mismas cosas " - Albert Einstein
  #9 (permalink)  
Antiguo 21/01/2010, 18:24
 
Fecha de Ingreso: junio-2003
Ubicación: Asturias
Mensajes: 2.429
Antigüedad: 20 años, 11 meses
Puntos: 7
Respuesta: Obtener nombre Monitor PC

Pero no vale con un simple system.net.dns.gethostname() ???
__________________
Charlie.
  #10 (permalink)  
Antiguo 22/01/2010, 01:05
Avatar de eperedo  
Fecha de Ingreso: septiembre-2009
Ubicación: Perú
Mensajes: 654
Antigüedad: 14 años, 7 meses
Puntos: 16
Respuesta: Obtener nombre Monitor PC

GetHostName es para obtener el nombre de equipo, no del monitor.

Como explico seba123neo con la clase ManagementObjectSearcher puedes obtenerlo.

Saludos.
__________________
Eduardo Peredo
Wigoin
  #11 (permalink)  
Antiguo 22/01/2010, 12:54
 
Fecha de Ingreso: junio-2003
Ubicación: Asturias
Mensajes: 2.429
Antigüedad: 20 años, 11 meses
Puntos: 7
Respuesta: Obtener nombre Monitor PC

jajajaja, perdon, estaba seguro de que estabamos hablando del ordenador... se me fue la cabeza.

Saludos.
__________________
Charlie.
  #12 (permalink)  
Antiguo 22/01/2010, 14:24
 
Fecha de Ingreso: marzo-2008
Mensajes: 37
Antigüedad: 16 años, 1 mes
Puntos: 0
Respuesta: Obtener nombre Monitor PC

Hola seba123neo primero agradecerte por la ayuda que me has estado brindando, pues probe el codigo que mencionas pero no muestra la marca del monitor a lo mejor sera porque mi monitor a lo mejor no es de marca original jajaja supongo que por eso no detecta , pues mi monitor es un view Sonic , pero nada no me vota el nombre del monitor ni la marca solo monitor plug and play y tipo monitor estandar, pues no se tu pero al menos yo he probado este codigo en varios equipos y digamos que del 50 equipos solo una 8 habra arrojado el nombre de monitor o marca.

Si hubiera alguna otra forma de obtener los datos bienvenida sea :-p

Saludos y Gracias
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:58.