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

 Delphi Discussion :

Avec D6 Informations du système avec Wmi pour l'Os Windows 10 64bits


Sujet :

Delphi

  1. #1
    Membre expérimenté
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 450
    Détails du profil
    Informations personnelles :
    Âge : 71
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 450
    Points : 1 336
    Points
    1 336
    Par défaut Avec D6 Informations du système avec Wmi pour l'Os Windows 10 64bits
    Bonjour à toutes et à tous,

    Avec une ancienne application et en me servant de la bas de registre et de ses clés, j'affichais les informations de mon Os Windows.

    Votre Os : Windows 10 Home

    Major version : 10

    Minor Version : 0

    Build : 19041.vb_release.191206-1406

    Releaseid : 2004

    Version 64 bits
    Je viens d'installer la mise à jour Windows 10 Edition 2004 64 bits, mon application m'affiche bien les changements.

    Est t'il possible de le faire avec Wmi ?

    Merci d'avance,

    @+,

    cincap

  2. #2
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 621
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 621
    Points : 25 321
    Points
    25 321

  3. #3
    Membre expérimenté
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 450
    Détails du profil
    Informations personnelles :
    Âge : 71
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 450
    Points : 1 336
    Points
    1 336
    Par défaut
    Bonjour à toutes et à tous,

    @ ShaiLeTroll Oups passer à coté de la recherche, je vais voir si adaptable à D6.

    J'avais vu des solutions avec Google mais aucune ne fonctionnait avec peu de ligne comme interrogé la base de registre.

    Merci pour ta recherche.

    @+,

    cincap

  4. #4
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 164
    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 164
    Points : 41 346
    Points
    41 346
    Billets dans le blog
    63
    Par défaut
    Bonjour

    Citation Envoyé par cincap Voir le message
    avec peu de ligne comme
    WMI et peu de ligne cela ne risque pas d'aller ensemble

    En tout cas WMi Delphi Code Creator sera un bon ami


    voilà ce que ce petit bijou propose comme génération de code (ici toutes les informations de root\cimv2 win32_operatingsytem.
    YAPLUKA élaguer (mais déjà vérifier que D6 accepte la compilation)

    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
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
     
    //-----------------------------------------------------------------------------------------------------
    //     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;
     
    function GetDataExecutionPrevention_SupportPolicyAsString(const ReturnValue:Integer) : string;
    begin
    Result:='';
      case ReturnValue of
        0 : Result:='Always Off';
        1 : Result:='Always On';
        2 : Result:='Opt In';
        3 : Result:='Opt Out';
      end;
    end;
     
    function GetEncryptionLevelAsString(const ReturnValue:Integer) : string;
    begin
    Result:='';
      case ReturnValue of
        0 : Result:='40 bits';
        1 : Result:='128 bits';
        2 : Result:='n bits';
      end;
    end;
     
    function GetForegroundApplicationBoostAsString(const ReturnValue:Integer) : string;
    begin
    Result:='';
      case ReturnValue of
        0 : Result:='Aucun';
        1 : Result:='Minimum';
        2 : Result:='Maximum';
      end;
    end;
     
    function GetLargeSystemCacheAsString(const ReturnValue:Integer) : string;
    begin
    Result:='';
      case ReturnValue of
        0 : Result:='Optimiser pour les applications';
        1 : Result:='Optimiser pour les performances système';
      end;
    end;
     
    function GetOperatingSystemSKUAsString(const ReturnValue:Integer) : string;
    begin
    Result:='';
      case ReturnValue of
        0 : Result:='Non défini';
        1 : Result:='Édition Intégrale';
        2 : Result:='Édition Familiale Basique';
        3 : Result:='Édition Familiale Premium';
        4 : Result:='Entreprise';
        5 : Result:='Édition Familiale Basique N';
        6 : Result:='Professionnel';
        7 : Result:='Standard Server Edition';
        8 : Result:='Datacenter Server Edition';
        9 : Result:='Small Business Server Edition';
        10 : Result:='Enterprise Server Edition';
        11 : Result:='Starter Edition';
        12 : Result:='Datacenter Server Core Edition';
        13 : Result:='Standard Server Core Edition';
        14 : Result:='Enterprise Server Core Edition';
        15 : Result:='Enterprise Server IA64 Edition';
        16 : Result:='Professionnel N';
        17 : Result:='Web Server Edition';
        18 : Result:='Cluster Server Edition';
        19 : Result:='Édition Serveur personnel';
        20 : Result:='Storage Express Server Edition';
        21 : Result:='Storage Standard Server Edition';
        22 : Result:='Storage Workgroup Server Edition';
        23 : Result:='Storage Enterprise Server Edition';
        24 : Result:='Server For Small Business Edition';
        25 : Result:='Small Business Server Premium Edition';
      end;
    end;
     
    function GetOSTypeAsString(const ReturnValue:Integer) : string;
    begin
    Result:='';
      case ReturnValue of
        0 : Result:='Inconnu';
        1 : Result:='Autre';
        2 : Result:='MACOS';
        3 : Result:='ATTUNIX';
        4 : Result:='DGUX';
        5 : Result:='DECNT';
        6 : Result:='Digital Unix';
        7 : Result:='OpenVMS';
        8 : Result:='HPUX';
        9 : Result:='AIX';
        10 : Result:='MVS';
        11 : Result:='OS400';
        12 : Result:='OS/2';
        13 : Result:='JavaVM';
        14 : Result:='MSDOS';
        15 : Result:='WIN3x';
        16 : Result:='WIN95';
        17 : Result:='WIN98';
        18 : Result:='WINNT';
        19 : Result:='WINCE';
        20 : Result:='NCR3000';
        21 : Result:='NetWare';
        22 : Result:='OSF';
        23 : Result:='DC/OS';
        24 : Result:='Reliant UNIX';
        25 : Result:='SCO UnixWare';
        26 : Result:='SCO OpenServer';
        27 : Result:='Sequent';
        28 : Result:='IRIX';
        29 : Result:='Solaris';
        30 : Result:='SunOS';
        31 : Result:='U6000';
        32 : Result:='ASERIES';
        33 : Result:='TandemNSK';
        34 : Result:='TandemNT';
        35 : Result:='BS2000';
        36 : Result:='LINUX';
        37 : Result:='Lynx';
        38 : Result:='XENIX';
        39 : Result:='VM/ESA';
        40 : Result:='Interactive UNIX';
        41 : Result:='BSDUNIX';
        42 : Result:='FreeBSD';
        43 : Result:='NetBSD';
        44 : Result:='GNU Hurd';
        45 : Result:='OS9';
        46 : Result:='MACH Kernel';
        47 : Result:='Inferno';
        48 : Result:='QNX';
        49 : Result:='EPOC';
        50 : Result:='IxWorks';
        51 : Result:='VxWorks';
        52 : Result:='MiNT';
        53 : Result:='BeOS';
        54 : Result:='HP MPE';
        55 : Result:='NextStep';
        56 : Result:='PalmPilot';
        57 : Result:='Rhapsody';
        58 : Result:='Windows 2000';
        59 : Result:='Dédié';
        60 : Result:='OS/390';
        61 : Result:='VSE';
        62 : Result:='TPF';
      end;
    end;
     
    function GetProductTypeAsString(const ReturnValue:Integer) : string;
    begin
    Result:='';
      case ReturnValue of
        1 : Result:='Station de travail';
        2 : Result:='Contrôleur de domaine';
        3 : Result:='Serveur';
      end;
    end;
     
     
     
    // La classe Win32_OperatingSystem représente un système d’exploitation installé sur un ordinateur Win32. Tout système d’exploitation qui peut être installé sur un système Win32 est un descendant (ou membre) de cette classe
    // Exemple*: Microsoft Windows 95.
     
    procedure  GetWin32_OperatingSystemInfo;
    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_OperatingSystem','WQL',wbemFlagForwardOnly);
      oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
      while oEnum.Next(1, FWbemObject, iValue) = 0 do
      begin
        Writeln(Format('BootDevice                                   %s',[String(FWbemObject.BootDevice)]));// String
        Writeln(Format('BuildNumber                                  %s',[String(FWbemObject.BuildNumber)]));// String
        Writeln(Format('BuildType                                    %s',[String(FWbemObject.BuildType)]));// String
        Writeln(Format('Caption                                      %s',[String(FWbemObject.Caption)]));// String
        Writeln(Format('CodeSet                                      %s',[String(FWbemObject.CodeSet)]));// String
        Writeln(Format('CountryCode                                  %s',[String(FWbemObject.CountryCode)]));// String
        Writeln(Format('CreationClassName                            %s',[String(FWbemObject.CreationClassName)]));// String
        Writeln(Format('CSCreationClassName                          %s',[String(FWbemObject.CSCreationClassName)]));// String
        Writeln(Format('CSDVersion                                   %s',[String(FWbemObject.CSDVersion)]));// String
        Writeln(Format('CSName                                       %s',[String(FWbemObject.CSName)]));// String
        Writeln(Format('CurrentTimeZone                              %d',[Integer(FWbemObject.CurrentTimeZone)]));// Sint16
        Writeln(Format('DataExecutionPrevention_32BitApplications    %s',[String(FWbemObject.DataExecutionPrevention_32BitApplications)]));// Boolean
        Writeln(Format('DataExecutionPrevention_Available            %s',[String(FWbemObject.DataExecutionPrevention_Available)]));// Boolean
        Writeln(Format('DataExecutionPrevention_Drivers              %s',[String(FWbemObject.DataExecutionPrevention_Drivers)]));// Boolean
        Writeln(Format('DataExecutionPrevention_SupportPolicy        %s',[GetDataExecutionPrevention_SupportPolicyAsString(FWbemObject.DataExecutionPrevention_SupportPolicy)]));// Uint8
        Writeln(Format('Debug                                        %s',[String(FWbemObject.Debug)]));// Boolean
        Writeln(Format('Description                                  %s',[String(FWbemObject.Description)]));// String
        Writeln(Format('Distributed                                  %s',[String(FWbemObject.Distributed)]));// Boolean
        Writeln(Format('EncryptionLevel                              %s',[GetEncryptionLevelAsString(FWbemObject.EncryptionLevel)]));// Uint32
        Writeln(Format('ForegroundApplicationBoost                   %s',[GetForegroundApplicationBoostAsString(FWbemObject.ForegroundApplicationBoost)]));// Uint8
        Writeln(Format('FreePhysicalMemory                           %d',[Integer(FWbemObject.FreePhysicalMemory)]));// Uint64
        Writeln(Format('FreeSpaceInPagingFiles                       %d',[Integer(FWbemObject.FreeSpaceInPagingFiles)]));// Uint64
        Writeln(Format('FreeVirtualMemory                            %d',[Integer(FWbemObject.FreeVirtualMemory)]));// Uint64
        Writeln(Format('InstallDate                                  %s',[String(FWbemObject.InstallDate)]));// Datetime
        Writeln(Format('LargeSystemCache                             %s',[GetLargeSystemCacheAsString(FWbemObject.LargeSystemCache)]));// Uint32
        Writeln(Format('LastBootUpTime                               %s',[String(FWbemObject.LastBootUpTime)]));// Datetime
        Writeln(Format('LocalDateTime                                %s',[String(FWbemObject.LocalDateTime)]));// Datetime
        Writeln(Format('Locale                                       %s',[String(FWbemObject.Locale)]));// String
        Writeln(Format('Manufacturer                                 %s',[String(FWbemObject.Manufacturer)]));// String
        Writeln(Format('MaxNumberOfProcesses                         %d',[Integer(FWbemObject.MaxNumberOfProcesses)]));// Uint32
        Writeln(Format('MaxProcessMemorySize                         %d',[Integer(FWbemObject.MaxProcessMemorySize)]));// Uint64
        Writeln(Format('MUILanguages                                 %s',[String(FWbemObject.MUILanguages)]));// Array of String
        Writeln(Format('Name                                         %s',[String(FWbemObject.Name)]));// String
        Writeln(Format('NumberOfLicensedUsers                        %d',[Integer(FWbemObject.NumberOfLicensedUsers)]));// Uint32
        Writeln(Format('NumberOfProcesses                            %d',[Integer(FWbemObject.NumberOfProcesses)]));// Uint32
        Writeln(Format('NumberOfUsers                                %d',[Integer(FWbemObject.NumberOfUsers)]));// Uint32
        Writeln(Format('OperatingSystemSKU                           %s',[GetOperatingSystemSKUAsString(FWbemObject.OperatingSystemSKU)]));// Uint32
        Writeln(Format('Organization                                 %s',[String(FWbemObject.Organization)]));// String
        Writeln(Format('OSArchitecture                               %s',[String(FWbemObject.OSArchitecture)]));// String
        Writeln(Format('OSLanguage                                   %d',[Integer(FWbemObject.OSLanguage)]));// Uint32
        Writeln(Format('OSProductSuite                               %d',[Integer(FWbemObject.OSProductSuite)]));// Uint32
        Writeln(Format('OSType                                       %s',[GetOSTypeAsString(FWbemObject.OSType)]));// Uint16
        Writeln(Format('OtherTypeDescription                         %s',[String(FWbemObject.OtherTypeDescription)]));// String
        Writeln(Format('PAEEnabled                                   %s',[String(FWbemObject.PAEEnabled)]));// Boolean
        Writeln(Format('PlusProductID                                %s',[String(FWbemObject.PlusProductID)]));// String
        Writeln(Format('PlusVersionNumber                            %s',[String(FWbemObject.PlusVersionNumber)]));// String
        Writeln(Format('PortableOperatingSystem                      %s',[String(FWbemObject.PortableOperatingSystem)]));// Boolean
        Writeln(Format('Primary                                      %s',[String(FWbemObject.Primary)]));// Boolean
        Writeln(Format('ProductType                                  %s',[GetProductTypeAsString(FWbemObject.ProductType)]));// Uint32
        Writeln(Format('RegisteredUser                               %s',[String(FWbemObject.RegisteredUser)]));// String
        Writeln(Format('SerialNumber                                 %s',[String(FWbemObject.SerialNumber)]));// String
        Writeln(Format('ServicePackMajorVersion                      %d',[Integer(FWbemObject.ServicePackMajorVersion)]));// Uint16
        Writeln(Format('ServicePackMinorVersion                      %d',[Integer(FWbemObject.ServicePackMinorVersion)]));// Uint16
        Writeln(Format('SizeStoredInPagingFiles                      %d',[Integer(FWbemObject.SizeStoredInPagingFiles)]));// Uint64
        Writeln(Format('Status                                       %s',[String(FWbemObject.Status)]));// String
        Writeln(Format('SuiteMask                                    %d',[Integer(FWbemObject.SuiteMask)]));// Uint32
        Writeln(Format('SystemDevice                                 %s',[String(FWbemObject.SystemDevice)]));// String
        Writeln(Format('SystemDirectory                              %s',[String(FWbemObject.SystemDirectory)]));// String
        Writeln(Format('SystemDrive                                  %s',[String(FWbemObject.SystemDrive)]));// String
        Writeln(Format('TotalSwapSpaceSize                           %d',[Integer(FWbemObject.TotalSwapSpaceSize)]));// Uint64
        Writeln(Format('TotalVirtualMemorySize                       %d',[Integer(FWbemObject.TotalVirtualMemorySize)]));// Uint64
        Writeln(Format('TotalVisibleMemorySize                       %d',[Integer(FWbemObject.TotalVisibleMemorySize)]));// Uint64
        Writeln(Format('Version                                      %s',[String(FWbemObject.Version)]));// String
        Writeln(Format('WindowsDirectory                             %s',[String(FWbemObject.WindowsDirectory)]));// String
     
        Writeln('');
        FWbemObject:=Unassigned;
      end;
    end;
     
     
    begin
     try
        CoInitialize(nil);
        try
          GetWin32_OperatingSystemInfo;
        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.

  5. #5
    Membre expérimenté
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 450
    Détails du profil
    Informations personnelles :
    Âge : 71
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 450
    Points : 1 336
    Points
    1 336
    Par défaut
    Bonjour à toutes et à tous,

    @ SergioMaster, grand merci pour ta suggestion et ton code en effet reste à épurer et tester avec D6 sous Windows 10 64bits édition 2004 (soit 20 avril et non l'année !).

    Dans mes tests je ne suis pas arrivé à afficher "2004" propriété "Releaseid".

    En fait, je pense que je vais rester sur ma version d'interroger la base de registre d'autant que c'est dans un but de connaissance supplémentaire.

    Bonne journée,

    @+,

    cincap

  6. #6
    Membre expert
    Avatar de Charly910
    Homme Profil pro
    Ingénieur TP
    Inscrit en
    Décembre 2006
    Messages
    2 388
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur TP
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Décembre 2006
    Messages : 2 388
    Points : 3 160
    Points
    3 160
    Par défaut
    Bonjour,
    j'ai testé le code de Serge avec D7. Sur mon W10 familly j'avais 7 ou 8 variants à Null qui généraient des erreur lors de la conversion en String. J'ai ajouté des tests (marqués "===Modif" dans le code). Il s'exécute bien maintenant, mais quelques items ne sont pas renseignés.

    (j'ai aussi ajouté des Else dans les Cases).

    Voici la version modifiée :

    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
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    //-----------------------------------------------------------------------------------------------------
    //     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
    //     Modif  Juin 2020  - Charly910
    //-----------------------------------------------------------------------------------------------------
    //
    //     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;
     
    function GetDataExecutionPrevention_SupportPolicyAsString(const ReturnValue:Integer) : string;
    begin
    Result:='';
      case ReturnValue of
        0 : Result:='Always Off';
        1 : Result:='Always On';
        2 : Result:='Opt In';
        3 : Result:='Opt Out';
      Else
        Result := 'Non défini' ;
      end;
    end;
     
    function GetEncryptionLevelAsString(const ReturnValue:Integer) : string;
    begin
    Result:='';
      case ReturnValue of
        0 : Result:='40 bits';
        1 : Result:='128 bits';
        2 : Result:='n bits';
      Else
        Result := 'Non défini' ;
      end;
    end;
     
    function GetForegroundApplicationBoostAsString(const ReturnValue:Integer) : string;
    begin
    Result:='';
      case ReturnValue of
        0 : Result:='Aucun';
        1 : Result:='Minimum';
        2 : Result:='Maximum';
      Else
        Result := 'Non défini' ;
      end;
    end;
     
    function GetLargeSystemCacheAsString(const ReturnValue:Integer) : string;
    begin
    Result:='';
      case ReturnValue of
        0 : Result:='Optimiser pour les applications';
        1 : Result:='Optimiser pour les performances système';
      Else
        Result := 'non défini' ;
      end;
    end;
     
    function GetOperatingSystemSKUAsString(const ReturnValue:Integer) : string;
    begin
    Result:='';
      case ReturnValue of
        0 : Result:='Non défini';
        1 : Result:='Édition Intégrale';
        2 : Result:='Édition Familiale Basique';
        3 : Result:='Édition Familiale Premium';
        4 : Result:='Entreprise';
        5 : Result:='Édition Familiale Basique N';
        6 : Result:='Professionnel';
        7 : Result:='Standard Server Edition';
        8 : Result:='Datacenter Server Edition';
        9 : Result:='Small Business Server Edition';
        10 : Result:='Enterprise Server Edition';
        11 : Result:='Starter Edition';
        12 : Result:='Datacenter Server Core Edition';
        13 : Result:='Standard Server Core Edition';
        14 : Result:='Enterprise Server Core Edition';
        15 : Result:='Enterprise Server IA64 Edition';
        16 : Result:='Professionnel N';
        17 : Result:='Web Server Edition';
        18 : Result:='Cluster Server Edition';
        19 : Result:='Édition Serveur personnel';
        20 : Result:='Storage Express Server Edition';
        21 : Result:='Storage Standard Server Edition';
        22 : Result:='Storage Workgroup Server Edition';
        23 : Result:='Storage Enterprise Server Edition';
        24 : Result:='Server For Small Business Edition';
        25 : Result:='Small Business Server Premium Edition';
        //  ===Modif
        Else
          Result := 'Non défini' ;
      end;
    end;
     
    function GetOSTypeAsString(const ReturnValue:Integer) : string;
    begin
    Result:='';
      case ReturnValue of
        0 : Result:='Inconnu';
        1 : Result:='Autre';
        2 : Result:='MACOS';
        3 : Result:='ATTUNIX';
        4 : Result:='DGUX';
        5 : Result:='DECNT';
        6 : Result:='Digital Unix';
        7 : Result:='OpenVMS';
        8 : Result:='HPUX';
        9 : Result:='AIX';
        10 : Result:='MVS';
        11 : Result:='OS400';
        12 : Result:='OS/2';
        13 : Result:='JavaVM';
        14 : Result:='MSDOS';
        15 : Result:='WIN3x';
        16 : Result:='WIN95';
        17 : Result:='WIN98';
        18 : Result:='WINNT';
        19 : Result:='WINCE';
        20 : Result:='NCR3000';
        21 : Result:='NetWare';
        22 : Result:='OSF';
        23 : Result:='DC/OS';
        24 : Result:='Reliant UNIX';
        25 : Result:='SCO UnixWare';
        26 : Result:='SCO OpenServer';
        27 : Result:='Sequent';
        28 : Result:='IRIX';
        29 : Result:='Solaris';
        30 : Result:='SunOS';
        31 : Result:='U6000';
        32 : Result:='ASERIES';
        33 : Result:='TandemNSK';
        34 : Result:='TandemNT';
        35 : Result:='BS2000';
        36 : Result:='LINUX';
        37 : Result:='Lynx';
        38 : Result:='XENIX';
        39 : Result:='VM/ESA';
        40 : Result:='Interactive UNIX';
        41 : Result:='BSDUNIX';
        42 : Result:='FreeBSD';
        43 : Result:='NetBSD';
        44 : Result:='GNU Hurd';
        45 : Result:='OS9';
        46 : Result:='MACH Kernel';
        47 : Result:='Inferno';
        48 : Result:='QNX';
        49 : Result:='EPOC';
        50 : Result:='IxWorks';
        51 : Result:='VxWorks';
        52 : Result:='MiNT';
        53 : Result:='BeOS';
        54 : Result:='HP MPE';
        55 : Result:='NextStep';
        56 : Result:='PalmPilot';
        57 : Result:='Rhapsody';
        58 : Result:='Windows 2000';
        59 : Result:='Dédié';
        60 : Result:='OS/390';
        61 : Result:='VSE';
        62 : Result:='TPF';
      //   ===Modif
      Else
        Result := 'Inconnu' ;
      end;
    end;
     
    function GetProductTypeAsString(const ReturnValue:Integer) : string;
    begin
    Result:='';
      case ReturnValue of
        1 : Result:='Station de travail';
        2 : Result:='Contrôleur de domaine';
        3 : Result:='Serveur';
      Else
        Result := 'Inconnu' ;  
      end;
    end;
     
     
     
    // La classe Win32_OperatingSystem représente un système d’exploitation installé sur un ordinateur Win32. Tout système d’exploitation qui peut être installé sur un système Win32 est un descendant (ou membre) de cette classe
    // Exemple*: Microsoft Windows 95.
     
    procedure  GetWin32_OperatingSystemInfo;
    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_OperatingSystem','WQL',wbemFlagForwardOnly);
      oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
      while oEnum.Next(1, FWbemObject, iValue) = 0 do
      begin
        Writeln(Format('BootDevice                                   %s',[String(FWbemObject.BootDevice)]));// String
        Writeln(Format('BuildNumber                                  %s',[String(FWbemObject.BuildNumber)]));// String
        Writeln(Format('BuildType                                    %s',[String(FWbemObject.BuildType)]));// String
        Writeln(Format('Caption                                      %s',[String(FWbemObject.Caption)]));// String
        Writeln(Format('CodeSet                                      %s',[String(FWbemObject.CodeSet)]));// String
        Writeln(Format('CountryCode                                  %s',[String(FWbemObject.CountryCode)]));// String
        Writeln(Format('CreationClassName                            %s',[String(FWbemObject.CreationClassName)]));// String
        Writeln(Format('CSCreationClassName                          %s',[String(FWbemObject.CSCreationClassName)]));// String
        If FWbemObject.CSDVersion <> Null Then
        Writeln(Format('CSDVersion                                   %s',[String(FWbemObject.CSDVersion)])) // String
        Else
        Writeln('CSDVersion                                   Nil') ;
        Writeln(Format('CSName                                       %s',[String(FWbemObject.CSName)]));// String
        Writeln(Format('CurrentTimeZone                              %d',[Integer(FWbemObject.CurrentTimeZone)]));// Sint16
        Writeln(Format('DataExecutionPrevention_32BitApplications    %s',[String(FWbemObject.DataExecutionPrevention_32BitApplications)]));// Boolean
        Writeln(Format('DataExecutionPrevention_Available            %s',[String(FWbemObject.DataExecutionPrevention_Available)]));// Boolean
        Writeln(Format('DataExecutionPrevention_Drivers              %s',[String(FWbemObject.DataExecutionPrevention_Drivers)]));// Boolean
        Writeln(Format('DataExecutionPrevention_SupportPolicy        %s',[GetDataExecutionPrevention_SupportPolicyAsString(FWbemObject.DataExecutionPrevention_SupportPolicy)]));// Uint8
        Writeln(Format('Debug                                        %s',[String(FWbemObject.Debug)]));// Boolean
        Writeln(Format('Description                                  %s',[String(FWbemObject.Description)]));// String
        Writeln(Format('Distributed                                  %s',[String(FWbemObject.Distributed)]));// Boolean
        Writeln(Format('EncryptionLevel                              %s',[GetEncryptionLevelAsString(FWbemObject.EncryptionLevel)]));// Uint32
        Writeln(Format('ForegroundApplicationBoost                   %s',[GetForegroundApplicationBoostAsString(FWbemObject.ForegroundApplicationBoost)]));// Uint8
        Writeln(Format('FreePhysicalMemory                           %d',[Integer(FWbemObject.FreePhysicalMemory)]));// Uint64
        Writeln(Format('FreeSpaceInPagingFiles                       %d',[Integer(FWbemObject.FreeSpaceInPagingFiles)]));// Uint64
        Writeln(Format('FreeVirtualMemory                            %d',[Integer(FWbemObject.FreeVirtualMemory)]));// Uint64
        Writeln(Format('InstallDate                                  %s',[String(FWbemObject.InstallDate)]));// Datetime
     
    //   Valeur nulle  ===Modif
        If FWbemObject.LargeSystemCache > 0 Then
        Writeln(Format('LargeSystemCache                             %s',[GetLargeSystemCacheAsString(FWbemObject.LargeSystemCache)])) // Uint32
        Else
        Writeln('LargeSystemCache                             0' ) ;
        Writeln(Format('LastBootUpTime                               %s',[String(FWbemObject.LastBootUpTime)]));// Datetime
        Writeln(Format('LocalDateTime                                %s',[String(FWbemObject.LocalDateTime)]));// Datetime
        Writeln(Format('Locale                                       %s',[String(FWbemObject.Locale)]));// String
        Writeln(Format('Manufacturer                                 %s',[String(FWbemObject.Manufacturer)]));// String
        Writeln(Format('MaxNumberOfProcesses                         %d',[Integer(FWbemObject.MaxNumberOfProcesses)]));// Uint32
    //   Débordement d'Integer  ===Modif
        If  FWbemObject.MaxProcessMemorySize <= 2147483647 Then
        Writeln(Format('MaxProcessMemorySize                         %d',[Integer(FWbemObject.MaxProcessMemorySize)]))// Uint64
        Else
        Writeln('MaxProcessMemorySize                         > 2147483647' ) ;
    //  Conversion en String impossible  ===Modif
    //    Writeln(Format('MUILanguages                                 %s',[String(FWbemObject.MUILanguages)]));// Array of String
        Writeln(Format('Name                                         %s',[String(FWbemObject.Name)]));// String
        Writeln(Format('NumberOfLicensedUsers                        %d',[Integer(FWbemObject.NumberOfLicensedUsers)]));// Uint32
        Writeln(Format('NumberOfProcesses                            %d',[Integer(FWbemObject.NumberOfProcesses)]));// Uint32
        Writeln(Format('NumberOfUsers                                %d',[Integer(FWbemObject.NumberOfUsers)]));// Uint32
        Writeln(Format('OperatingSystemSKU                           %s',[GetOperatingSystemSKUAsString(FWbemObject.OperatingSystemSKU)]));// Uint32
        Writeln(Format('Organization                                 %s',[String(FWbemObject.Organization)]));// String
        Writeln(Format('OSArchitecture                               %s',[String(FWbemObject.OSArchitecture)]));// String
        Writeln(Format('OSLanguage                                   %d',[Integer(FWbemObject.OSLanguage)]));// Uint32
        Writeln(Format('OSProductSuite                               %d',[Integer(FWbemObject.OSProductSuite)]));// Uint32
        Writeln(Format('OSType                                       %s',[GetOSTypeAsString(FWbemObject.OSType)]));// Uint16
    //  Variant de type Null    ===Modif
        If FWbemObject.OtherTypeDescription <> Null Then
        Writeln(Format('OtherTypeDescription                         %s',[String(FWbemObject.OtherTypeDescription)]))// String
        Else
        Writeln('OtherTypeDescription                         Nil' ) ;
    //  Variant Null   ===Modif
        If FWbemObject.PAEEnabled <> Null Then
        Writeln(Format('PAEEnabled                                   %s',[String(FWbemObject.PAEEnabled)])) // Boolean
        Else
        Writeln('PAEEnabled                                   Nil') ;
    //  Variant Null   ===Modif
        If FWbemObject.PlusProductID <> Null Then
        Writeln(Format('PlusProductID                                %s',[String(FWbemObject.PlusProductID)])) // String
        Else
        Writeln('PlusProductID                                Nil') ;
    //  Variant Null   ===Modif
        If FWbemObject.PlusVersionNumber <> Null Then
     
        Writeln(Format('PlusVersionNumber                            %s',[String(FWbemObject.PlusVersionNumber)])) // String
        Else
        Writeln('PlusVersionNumber                            Nil') ;
        Writeln(Format('PortableOperatingSystem                      %s',[String(FWbemObject.PortableOperatingSystem)]));// Boolean
        Writeln(Format('Primary                                      %s',[String(FWbemObject.Primary)]));// Boolean
        Writeln(Format('ProductType                                  %s',[GetProductTypeAsString(FWbemObject.ProductType)]));// Uint32
        Writeln(Format('RegisteredUser                               %s',[String(FWbemObject.RegisteredUser)]));// String
        Writeln(Format('SerialNumber                                 %s',[String(FWbemObject.SerialNumber)]));// String
        Writeln(Format('ServicePackMajorVersion                      %d',[Integer(FWbemObject.ServicePackMajorVersion)]));// Uint16
        Writeln(Format('ServicePackMinorVersion                      %d',[Integer(FWbemObject.ServicePackMinorVersion)]));// Uint16
        Writeln(Format('SizeStoredInPagingFiles                      %d',[Integer(FWbemObject.SizeStoredInPagingFiles)]));// Uint64
        Writeln(Format('Status                                       %s',[String(FWbemObject.Status)]));// String
        Writeln(Format('SuiteMask                                    %d',[Integer(FWbemObject.SuiteMask)]));// Uint32
        Writeln(Format('SystemDevice                                 %s',[String(FWbemObject.SystemDevice)]));// String
        Writeln(Format('SystemDirectory                              %s',[String(FWbemObject.SystemDirectory)]));// String
        Writeln(Format('SystemDrive                                  %s',[String(FWbemObject.SystemDrive)]));// String
     
    //  Variant Null   ===Modif
        If FWbemObject.TotalSwapSpaceSize <> Null Then
     
        Writeln(Format('TotalSwapSpaceSize                           %d',[Integer(FWbemObject.TotalSwapSpaceSize)])) // Uint64
        Else
        Writeln('TotalSwapSpaceSize                           Nil') ;
        Writeln(Format('TotalVirtualMemorySize                       %d',[Integer(FWbemObject.TotalVirtualMemorySize)]));// Uint64
        Writeln(Format('TotalVisibleMemorySize                       %d',[Integer(FWbemObject.TotalVisibleMemorySize)]));// Uint64
        Writeln(Format('Version                                      %s',[String(FWbemObject.Version)]));// String
        Writeln(Format('WindowsDirectory                             %s',[String(FWbemObject.WindowsDirectory)]));// String
     
        Writeln('');
        FWbemObject:=Unassigned;
      end;
    end;
     
     
    begin
     try
        CoInitialize(nil);
        try
          GetWin32_OperatingSystemInfo;
        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.
    A+
    Charly

  7. #7
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 164
    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 164
    Points : 41 346
    Points
    41 346
    Billets dans le blog
    63
    Par défaut
    Citation Envoyé par Charly910 Voir le message
    ,
    j'ai testé le code de Serge avec D7.
    Ce n'est pas le mien, c'est celui généré par WMI Delphi Code Creator, le seul truc est que je n'ai peut-être pas généré correctement (options helpers et cie.)

  8. #8
    Membre expert
    Avatar de Charly910
    Homme Profil pro
    Ingénieur TP
    Inscrit en
    Décembre 2006
    Messages
    2 388
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur TP
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Décembre 2006
    Messages : 2 388
    Points : 3 160
    Points
    3 160
    Par défaut
    j'aurai du dire "fourni par Serge" ...

    le code est correct seulement, quand une variable Variant renvoie Nil, la conversion en String échoue.

    Je ne sais pas si mes modifs sont correctes, mais le code s’exécute bien. Certaines variables ne renvoient rien, je ne sais pas pourquoi ?

    Il y a juste le débordement d'Integer de FWbemObject.MaxProcessMemorySize que je n'ai pas su gérer alors j'ai bridé la valeur.

    A+
    Charly

  9. #9
    Membre éprouvé
    Avatar de Cirec
    Profil pro
    Inscrit en
    Octobre 2010
    Messages
    467
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2010
    Messages : 467
    Points : 1 073
    Points
    1 073
    Par défaut
    Bonjour,

    comme Charly910, j'ai fait le teste avec D6 (pour cincap) et avec D10.3
    le code fonctionne et tient compte des variables vides
    les accents sont affichés correctement ainsi que les booléens (en lettres)

    il reste encore les dates à convertir.

    j'ai du mettre une ligne en commentaire :
    { "PortableOperatingSystem" non supporté sous Win7 }
    le code:
    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
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
     
    //-----------------------------------------------------------------------------------------------------
    //     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
      windows,
      SysUtils,
      ActiveX,
      ComObj,
      Variants;
     
    function ConsoleString(const Chaine: string): string;
    begin
    {$ifdef unicode}
       Result := Chaine;
    {$else}
      SetLength(Result, Length(Chaine));
      if Chaine <> EmptyStr then
        CharToOem(PChar(Chaine), PChar(Result));
    {$endif}
    end;
     
    function VarToString(aVariant: Variant): string;
    begin
      Result := ConsoleString(VarToStr(aVariant));
    end;
     
    function VarToBoolString(aVariant: Variant): string;
    begin
      if not VarIsNull(aVariant) then
        Result := BoolToStr(aVariant, True)
      else
        Result := '';
    end;
     
     
    function VarToInteger(aVariant: Variant): Integer;
    begin
      if not VarIsNull(aVariant) then
        Result := Integer(aVariant)
      else
        Result := 0;
    end;
     
    function GetDataExecutionPrevention_SupportPolicyAsString(const ReturnValue: Integer): string;
    begin
      Result := '';
      case ReturnValue of
        0: Result := 'Always Off';
        1: Result := 'Always On';
        2: Result := 'Opt In';
        3: Result := 'Opt Out';
      end;
    end;
     
    function GetEncryptionLevelAsString(const ReturnValue: Integer): string;
    begin
      Result := '';
      case ReturnValue of
        0: Result := '40 bits';
        1: Result := '128 bits';
        2: Result := 'n bits';
      end;
    end;
     
    function GetForegroundApplicationBoostAsString(const ReturnValue: Integer): string;
    begin
      Result := '';
      case ReturnValue of
        0: Result := 'Aucun';
        1: Result := 'Minimum';
        2: Result := 'Maximum';
      end;
    end;
     
    function GetLargeSystemCacheAsString(const ReturnValue: Integer): string;
    begin
      Result := '';
      case ReturnValue of
        0: Result := 'Optimiser pour les applications';
        1: Result := 'Optimiser pour les performances système';
      end;
      Result := ConsoleString(Result);
    end;
     
    function GetOperatingSystemSKUAsString(const ReturnValue: Integer): string;
    begin
      Result := '';
      case ReturnValue of
        0: Result := 'Non défini';
        1: Result := 'Édition Intégrale';
        2: Result := 'Édition Familiale Basique';
        3: Result := 'Édition Familiale Premium';
        4: Result := 'Entreprise';
        5: Result := 'Édition Familiale Basique N';
        6: Result := 'Professionnel';
        7: Result := 'Standard Server Edition';
        8: Result := 'Datacenter Server Edition';
        9: Result := 'Small Business Server Edition';
        10: Result := 'Enterprise Server Edition';
        11: Result := 'Starter Edition';
        12: Result := 'Datacenter Server Core Edition';
        13: Result := 'Standard Server Core Edition';
        14: Result := 'Enterprise Server Core Edition';
        15: Result := 'Enterprise Server IA64 Edition';
        16: Result := 'Professionnel N';
        17: Result := 'Web Server Edition';
        18: Result := 'Cluster Server Edition';
        19: Result := 'Édition Serveur personnel';
        20: Result := 'Storage Express Server Edition';
        21: Result := 'Storage Standard Server Edition';
        22: Result := 'Storage Workgroup Server Edition';
        23: Result := 'Storage Enterprise Server Edition';
        24: Result := 'Server For Small Business Edition';
        25: Result := 'Small Business Server Premium Edition';
      end;
      Result := ConsoleString(Result);
    end;
     
    function GetOSTypeAsString(const ReturnValue: Integer): string;
    begin
      Result := '';
      case ReturnValue of
        0: Result := 'Inconnu';
        1: Result := 'Autre';
        2: Result := 'MACOS';
        3: Result := 'ATTUNIX';
        4: Result := 'DGUX';
        5: Result := 'DECNT';
        6: Result := 'Digital Unix';
        7: Result := 'OpenVMS';
        8: Result := 'HPUX';
        9: Result := 'AIX';
        10: Result := 'MVS';
        11: Result := 'OS400';
        12: Result := 'OS/2';
        13: Result := 'JavaVM';
        14: Result := 'MSDOS';
        15: Result := 'WIN3x';
        16: Result := 'WIN95';
        17: Result := 'WIN98';
        18: Result := 'WINNT';
        19: Result := 'WINCE';
        20: Result := 'NCR3000';
        21: Result := 'NetWare';
        22: Result := 'OSF';
        23: Result := 'DC/OS';
        24: Result := 'Reliant UNIX';
        25: Result := 'SCO UnixWare';
        26: Result := 'SCO OpenServer';
        27: Result := 'Sequent';
        28: Result := 'IRIX';
        29: Result := 'Solaris';
        30: Result := 'SunOS';
        31: Result := 'U6000';
        32: Result := 'ASERIES';
        33: Result := 'TandemNSK';
        34: Result := 'TandemNT';
        35: Result := 'BS2000';
        36: Result := 'LINUX';
        37: Result := 'Lynx';
        38: Result := 'XENIX';
        39: Result := 'VM/ESA';
        40: Result := 'Interactive UNIX';
        41: Result := 'BSDUNIX';
        42: Result := 'FreeBSD';
        43: Result := 'NetBSD';
        44: Result := 'GNU Hurd';
        45: Result := 'OS9';
        46: Result := 'MACH Kernel';
        47: Result := 'Inferno';
        48: Result := 'QNX';
        49: Result := 'EPOC';
        50: Result := 'IxWorks';
        51: Result := 'VxWorks';
        52: Result := 'MiNT';
        53: Result := 'BeOS';
        54: Result := 'HP MPE';
        55: Result := 'NextStep';
        56: Result := 'PalmPilot';
        57: Result := 'Rhapsody';
        58: Result := 'Windows 2000';
        59: Result := 'Dédié';
        60: Result := 'OS/390';
        61: Result := 'VSE';
        62: Result := 'TPF';
      end;
      Result := ConsoleString(Result);
    end;
     
    function GetProductTypeAsString(const ReturnValue: Integer): string;
    begin
      Result := '';
      case ReturnValue of
        1: Result := 'Station de travail';
        2: Result := 'Contrôleur de domaine';
        3: Result := 'Serveur';
      end;
      Result := ConsoleString(Result);
    end;
     
    // La classe Win32_OperatingSystem représente un système d’exploitation installé sur un ordinateur Win32. Tout système d’exploitation qui peut être installé sur un système Win32 est un descendant (ou membre) de cette classe
    // Exemple*: Microsoft Windows 95.
     
    procedure GetWin32_OperatingSystemInfo;
    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_OperatingSystem', 'WQL', wbemFlagForwardOnly);
      oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
      while oEnum.Next(1, FWbemObject, iValue) = 0 do
      begin
        Writeln(Format('BootDevice                                   %s', [VarToString(FWbemObject.BootDevice)])); // String
        Writeln(Format('BuildNumber                                  %s', [VarToString(FWbemObject.BuildNumber)])); // String
        Writeln(Format('BuildType                                    %s', [VarToString(FWbemObject.BuildType)])); // String
        Writeln(Format('Caption                                      %s', [VarToString(FWbemObject.Caption)])); // String
        Writeln(Format('CodeSet                                      %s', [VarToString(FWbemObject.CodeSet)])); // String
        Writeln(Format('CountryCode                                  %s', [VarToString(FWbemObject.CountryCode)])); // String
        Writeln(Format('CreationClassName                            %s', [VarToString(FWbemObject.CreationClassName)])); // String
        Writeln(Format('CSCreationClassName                          %s', [VarToString(FWbemObject.CSCreationClassName)])); // String
        Writeln(Format('CSDVersion                                   %s', [VarToString(FWbemObject.CSDVersion)])); // String
        Writeln(Format('CSName                                       %s', [VarToString(FWbemObject.CSName)])); // String
        Writeln(Format('CurrentTimeZone                              %d', [VarToInteger(FWbemObject.CurrentTimeZone)])); // Sint16
        Writeln(Format('DataExecutionPrevention_32BitApplications    %s', [VarToString(FWbemObject.DataExecutionPrevention_32BitApplications)])); // Boolean
        Writeln(Format('DataExecutionPrevention_Available            %s', [VarToString(FWbemObject.DataExecutionPrevention_Available)])); // Boolean
        Writeln(Format('DataExecutionPrevention_Drivers              %s', [VarToString(FWbemObject.DataExecutionPrevention_Drivers)])); // Boolean
        Writeln(Format('DataExecutionPrevention_SupportPolicy        %s', [GetDataExecutionPrevention_SupportPolicyAsString(FWbemObject.DataExecutionPrevention_SupportPolicy)])); // Uint8
        Writeln(Format('Debug                                        %s', [VarToBoolString(FWbemObject.Debug)])); // Boolean
        Writeln(Format('Description                                  %s', [VarToString(FWbemObject.Description)])); // String
        Writeln(Format('Distributed                                  %s', [VarToBoolString(FWbemObject.Distributed)])); // Boolean
        Writeln(Format('EncryptionLevel                              %s', [GetEncryptionLevelAsString(FWbemObject.EncryptionLevel)])); // Uint32
        Writeln(Format('ForegroundApplicationBoost                   %s', [GetForegroundApplicationBoostAsString(FWbemObject.ForegroundApplicationBoost)])); // Uint8
        Writeln(Format('FreePhysicalMemory                           %d', [VarToInteger(FWbemObject.FreePhysicalMemory)])); // Uint64
        Writeln(Format('FreeSpaceInPagingFiles                       %d', [VarToInteger(FWbemObject.FreeSpaceInPagingFiles)])); // Uint64
        Writeln(Format('FreeVirtualMemory                            %d', [VarToInteger(FWbemObject.FreeVirtualMemory)])); // Uint64
        Writeln(Format('InstallDate                                  %s', [VarToString((FWbemObject.InstallDate))])); // Datetime
        Writeln(Format('LargeSystemCache                             %s', [GetLargeSystemCacheAsString(StrToIntDef(VarToStr(FWbemObject.LargeSystemCache), 0))])); // Uint32
        Writeln(Format('LastBootUpTime                               %s', [VarToString(FWbemObject.LastBootUpTime)])); // Datetime
        Writeln(Format('LocalDateTime                                %s', [VarToString(FWbemObject.LocalDateTime)])); // Datetime
        Writeln(Format('Locale                                       %s', [VarToString(FWbemObject.Locale)])); // String
        Writeln(Format('Manufacturer                                 %s', [VarToString(FWbemObject.Manufacturer)])); // String
        Writeln(Format('MaxNumberOfProcesses                         %d', [VarToInteger(FWbemObject.MaxNumberOfProcesses)])); // Uint32
        Writeln(Format('MaxProcessMemorySize                         %d', [VarToInteger(FWbemObject.MaxProcessMemorySize)])); // Uint64
        Writeln(Format('MUILanguages                                 %s', [string(VarArrayGet(FWbemObject.MUILanguages, [0]))])); // Array of String
        Writeln(Format('Name                                         %s', [VarToString(FWbemObject.Name)])); // String
        Writeln(Format('NumberOfLicensedUsers                        %d', [VarToInteger(FWbemObject.NumberOfLicensedUsers)]));// Uint32
        Writeln(Format('NumberOfProcesses                            %d', [VarToInteger(FWbemObject.NumberOfProcesses)])); // Uint32
        Writeln(Format('NumberOfUsers                                %d', [VarToInteger(FWbemObject.NumberOfUsers)])); // Uint32
        Writeln(Format('OperatingSystemSKU                           %s', [GetOperatingSystemSKUAsString(FWbemObject.OperatingSystemSKU)])); // Uint32
        Writeln(Format('Organization                                 %s', [VarToString(FWbemObject.Organization)])); // String
        Writeln(Format('OSArchitecture                               %s', [VarToString(FWbemObject.OSArchitecture)])); // String
        Writeln(Format('OSLanguage                                   %d', [VarToInteger(FWbemObject.OSLanguage)])); // Uint32
        Writeln(Format('OSProductSuite                               %d', [VarToInteger(FWbemObject.OSProductSuite)])); // Uint32
        Writeln(Format('OSType                                       %s', [GetOSTypeAsString(FWbemObject.OSType)])); // Uint16
        Writeln(Format('OtherTypeDescription                         %s', [VarToString(FWbemObject.OtherTypeDescription)])); // String
        Writeln(Format('PAEEnabled                                   %s', [VarToBoolString(FWbemObject.PAEEnabled)])); // Boolean
        Writeln(Format('PlusProductID                                %s', [VarToString(FWbemObject.PlusProductID)])); // String
        Writeln(Format('PlusVersionNumber                            %s', [VarToString(FWbemObject.PlusVersionNumber)])); // String
    { "PortableOperatingSystem" non supporté sous Win7  }
    //    Writeln(Format('PortableOperatingSystem                      %s', [VarToString(FWbemObject.PortableOperatingSystem)]));// Boolean
        Writeln(Format('Primary                                      %s', [VarToString(FWbemObject.Primary)])); // Boolean
        Writeln(Format('ProductType                                  %s', [GetProductTypeAsString(FWbemObject.ProductType)])); // Uint32
        Writeln(Format('RegisteredUser                               %s', [VarToString(FWbemObject.RegisteredUser)])); // String
        Writeln(Format('SerialNumber                                 %s', [VarToString(FWbemObject.SerialNumber)])); // String
        Writeln(Format('ServicePackMajorVersion                      %d', [VarToInteger(FWbemObject.ServicePackMajorVersion)])); // Uint16
        Writeln(Format('ServicePackMinorVersion                      %d', [VarToInteger(FWbemObject.ServicePackMinorVersion)])); // Uint16
        Writeln(Format('SizeStoredInPagingFiles                      %d', [VarToInteger(FWbemObject.SizeStoredInPagingFiles)])); // Uint64
        Writeln(Format('Status                                       %s', [VarToString(FWbemObject.Status)])); // String
        Writeln(Format('SuiteMask                                    %d', [Integer(FWbemObject.SuiteMask)])); // Uint32
        Writeln(Format('SystemDevice                                 %s', [VarToString(FWbemObject.SystemDevice)])); // String
        Writeln(Format('SystemDirectory                              %s', [VarToString(FWbemObject.SystemDirectory)])); // String
        Writeln(Format('SystemDrive                                  %s', [VarToString(FWbemObject.SystemDrive)])); // String
        Writeln(Format('TotalSwapSpaceSize                           %d', [StrToIntDef(VarToStr(FWbemObject.TotalSwapSpaceSize), 0)])); // Uint64
        Writeln(Format('TotalVirtualMemorySize                       %d', [VarToInteger(FWbemObject.TotalVirtualMemorySize)])); // Uint64
        Writeln(Format('TotalVisibleMemorySize                       %d', [VarToInteger(FWbemObject.TotalVisibleMemorySize)])); // Uint64
        Writeln(Format('Version                                      %s', [VarToString(FWbemObject.Version)])); // String
        Writeln(Format('WindowsDirectory                             %s', [VarToString(FWbemObject.WindowsDirectory)])); // String
     
        Writeln('');
        FWbemObject := Unassigned;
      end;
    end;
     
     
    begin
      try
        CoInitialize(nil);
        try
          GetWin32_OperatingSystemInfo;
        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.
    Cordialement,

    @+

  10. #10
    Membre expert
    Avatar de Charly910
    Homme Profil pro
    Ingénieur TP
    Inscrit en
    Décembre 2006
    Messages
    2 388
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur TP
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Décembre 2006
    Messages : 2 388
    Points : 3 160
    Points
    3 160
    Par défaut
    Effectivement, j'avais vu que les dates étaient mal décodées.

    A+
    Charly

  11. #11
    Membre expérimenté
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 450
    Détails du profil
    Informations personnelles :
    Âge : 71
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 450
    Points : 1 336
    Points
    1 336
    Par défaut
    Bonjour à toutes et à tous,

    @ Tous, merci pour tous vos efforts et suggestions, cela permet d'avoir une idée de ce que l'on peut faire avec Wmi.

    Sinon avec les touches "Windows et R" puis tapez "Winver", on obtient la fiche Windows10, la version et 2004.

    En ce qui me concerne, en interrogeant la base de registre (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion), j'ai les indications qui m'intéressent.

    On pourrait dire que le topic est fermé.

    @+,

    cincap

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 28/03/2020, 07h54
  2. [Toutes versions] Informations sur les Moniteurs avec WMI ?
    Par Oliv- dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 23/06/2015, 15h05
  3. Réponses: 0
    Dernier message: 05/05/2012, 10h25
  4. Réponses: 4
    Dernier message: 05/04/2011, 08h31
  5. [Système] Cherche solution pour coupler PHP avec UNIX
    Par Delphy113 dans le forum Langage
    Réponses: 4
    Dernier message: 05/10/2006, 16h32

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