IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API, COM et SDKs Delphi Discussion :

Moniteur sous tension ou pas


Sujet :

API, COM et SDKs Delphi

  1. #1
    Membre Expert

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2007
    Messages
    3 526
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2007
    Messages : 3 526
    Par défaut Moniteur sous tension ou pas
    Bonjour

    J'ai retrouvé sur le forum un fil de 2005 qui dit qu'il n'est pas pas possible de savoir si un moniteur est "sous tension" ou pas.
    Mais aujourd'hui, ça a peut-être changé ?
    Pour l'instant je ne trouve rien sur le net à part des méthodes pour allumer ou éteindre un moniteur.
    Moi je veux juste savoir si, un moniteur est allumé ou pas.

    Une idée ?

  2. #2
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 567
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 567
    Billets dans le blog
    65
    Par défaut
    Bonjour, tu as fouillé du côté des WMIs ?

    Root/CIMV2/W32DesktopMonitor te dira si (entre autres) le PowerManagement est possible. Après, ...

  3. #3
    Membre Expert

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2007
    Messages
    3 526
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2007
    Messages : 3 526
    Par défaut
    J'ai trouvé et adapté le code ci-dessous :
    Mais il me répond que mes 2 moniteurs sont active = True même si j'en éteins un.
    Je vais regarder du côté de la classe W32DesktopMonitor que tu m'indiques.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
     
    //-----------------------------------------------------------------------------------------------------
    //     This code was generated by the Wmi Delphi Code Creator (WDCC) Version 1.9.9.482
    //     http://code.google.com/p/wmi-delphi-code-creator/
    //     Blog http://theroadtodelphi.wordpress.com/wmi-delphi-code-creator/
    //     Author Rodrigo Ruz V. (RRUZ) Copyright (C) 2011-2015
    //-----------------------------------------------------------------------------------------------------
    //
    //     LIABILITY DISCLAIMER
    //     THIS GENERATED CODE IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED.
    //     YOU USE IT AT YOUR OWN RISK. THE AUTHOR NOT WILL BE LIABLE FOR DATA LOSS,
    //     DAMAGES AND LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS CODE.
    //
    //----------------------------------------------------------------------------------------------------
    program GestionMoniteurs;
     
    {$APPTYPE CONSOLE}
     
    uses
      SysUtils,
      ActiveX,
      ComObj,
      Variants;
     
     
     
    // Monitor ID
     
    procedure  GetWmiMonitorIDInfo;
    const
      WbemUser            ='';
      WbemPassword        ='';
      WbemComputer        ='localhost';
      wbemFlagForwardOnly = $00000020;
    var
      FSWbemLocator : OLEVariant;
      FWMIService   : OLEVariant;
      FWbemObjectSet: OLEVariant;
      FWbemObject   : OLEVariant;
      oEnum         : IEnumvariant;
      iValue        : LongWord;
      I, J: Integer;
      S: string;
    begin;
      FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
      FWMIService   := FSWbemLocator.ConnectServer(WbemComputer, 'root\WMI', WbemUser, WbemPassword);
      FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM WmiMonitorID','WQL',wbemFlagForwardOnly);
      oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
      while oEnum.Next(1, FWbemObject, iValue) = 0 do
      begin
        Writeln(Format('Active                    %s',[String(FWbemObject.Active)]));// Boolean
        Writeln(Format('InstanceName              %s',[String(FWbemObject.InstanceName)]));// String
     
        S := '';
        for I := 0 to 15 do
          S := S + Chr(Byte(FWbemObject.ManufacturerName[I]));
        Writeln('ManufacturerName : ' + Trim(S));
     
        S := '';
        for I := 0 to 15 do
          S := S + Chr(Byte(FWbemObject.ProductCodeID[I]));
        Writeln(Trim('ProductCodeID : ' + S));
     
        S := '';
        for I := 0 to 15 do
          S := S + Chr(Byte(FWbemObject.SerialNumberID[I]));
        Writeln(Trim('SerialNumberID : ' + S));
     
     
        S := '';
        J := Integer(FWbemObject.UserFriendlyNameLength);
        for I := 0 to J - 1 do
          S := S + Chr(Byte(FWbemObject.UserFriendlyName[I]));
        Writeln('UserFriendlyName : ' + S);// Array of Uint16
     
        Writeln(Format('WeekOfManufacture         %d',[Integer(FWbemObject.WeekOfManufacture)]));// Uint8
        Writeln(Format('YearOfManufacture         %d',[Integer(FWbemObject.YearOfManufacture)]));// Uint16
     
        Writeln('');
        FWbemObject:=Unassigned;
      end;
    end;
     
     
    begin
     try
        CoInitialize(nil);
        try
          GetWmiMonitorIDInfo;
        finally
          CoUninitialize;
        end;
     except
        on E:EOleException do
            Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
        on E:Exception do
            Writeln(E.Classname, ':', E.Message);
     end;
     Writeln('Press Enter to exit');
     Readln;
    end.

  4. #4
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 567
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 567
    Billets dans le blog
    65
    Par défaut
    Tu avais donc bien fouillé les WMIs

  5. #5
    Membre Expert

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2007
    Messages
    3 526
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2007
    Messages : 3 526
    Par défaut
    Bon, avec le W32DesktopMonitor ça ne renvoie des infos que pour un seul moniteur (alors que 2 sont allumés) et franchement, c'est pas très parlant :-(


    Availability 8
    Caption Moniteur Plug-and-Play générique
    Description Moniteur Plug-and-Play générique
    DeviceID DesktopMonitor1
    Name Moniteur Plug-and-Play générique
    Status OK

    Press Enter to exit

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    //-----------------------------------------------------------------------------------------------------
    //     This code was generated by the Wmi Delphi Code Creator (WDCC) Version 1.9.9.482
    //     http://code.google.com/p/wmi-delphi-code-creator/
    //     Blog http://theroadtodelphi.wordpress.com/wmi-delphi-code-creator/
    //     Author Rodrigo Ruz V. (RRUZ) Copyright (C) 2011-2015 
    //----------------------------------------------------------------------------------------------------- 
    //
    //     LIABILITY DISCLAIMER
    //     THIS GENERATED CODE IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED.
    //     YOU USE IT AT YOUR OWN RISK. THE AUTHOR NOT WILL BE LIABLE FOR DATA LOSS,
    //     DAMAGES AND LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS CODE.
    //
    //----------------------------------------------------------------------------------------------------
    program GetWMI_Info;
     
    {$APPTYPE CONSOLE}
     
    uses
      SysUtils,
      ActiveX,
      ComObj,
      Variants;
     
     
     
    // La classe Win32_DesktopMonitor représente le type de moniteur ou périphérique 
    // d’affichage attaché au système de l’ordinateur.
     
    procedure  GetWin32_DesktopMonitorInfo;
    const
      WbemUser            ='';
      WbemPassword        ='';
      WbemComputer        ='localhost';
      wbemFlagForwardOnly = $00000020;
    var
      FSWbemLocator : OLEVariant;
      FWMIService   : OLEVariant;
      FWbemObjectSet: OLEVariant;
      FWbemObject   : OLEVariant;
      oEnum         : IEnumvariant;
      iValue        : LongWord;
    begin;
      FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
      FWMIService   := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
      FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_DesktopMonitor','WQL',wbemFlagForwardOnly);
      oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
      while oEnum.Next(1, FWbemObject, iValue) = 0 do
      begin
        Writeln(Format('Availability    %d',[Integer(FWbemObject.Availability)]));// Uint16
        Writeln(Format('Caption         %s',[String(FWbemObject.Caption)]));// String
        Writeln(Format('Description     %s',[String(FWbemObject.Description)]));// String
        Writeln(Format('DeviceID        %s',[String(FWbemObject.DeviceID)]));// String
    //    Writeln(Format('DisplayType     %d',[Integer(FWbemObject.DisplayType)]));// Uint16
        Writeln(Format('Name            %s',[String(FWbemObject.Name)]));// String
        Writeln(Format('Status          %s',[String(FWbemObject.Status)]));// String
     
        Writeln('');
        FWbemObject:=Unassigned;
      end;
    end;
     
     
    begin
     try
        CoInitialize(nil);
        try
          GetWin32_DesktopMonitorInfo;
        finally
          CoUninitialize;
        end;
     except
        on E:EOleException do
            Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode])); 
        on E:Exception do
            Writeln(E.Classname, ':', E.Message);
     end;
     Writeln('Press Enter to exit');
     Readln;      
    end.

Discussions similaires

  1. Menu dynamique marchant sous FF mais pas sous IE
    Par T-durden dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 18/08/2005, 14h14
  2. Réponses: 2
    Dernier message: 06/06/2005, 15h13
  3. probleme de couleur de fond sous mozilla et pas sous IE
    Par soccernet dans le forum Balisage (X)HTML et validation W3C
    Réponses: 7
    Dernier message: 27/12/2004, 10h45
  4. [CR8.5] Obligé d'utiliser un sous-rapport ou pas ?
    Par liberio dans le forum SAP Crystal Reports
    Réponses: 2
    Dernier message: 09/06/2004, 18h10
  5. Réponses: 2
    Dernier message: 04/06/2004, 11h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo