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

Langage Delphi Discussion :

Définir l'OS de la machine


Sujet :

Langage Delphi

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 30
    Points : 26
    Points
    26
    Par défaut Définir l'OS de la machine
    Bonjour,

    je développe un fichier d'installation pour un logiciel qui doit être installé que sur un serveur. J'ai créé un shellExecute
    Systeminfo | findstr "OSName" >> ...\OSName.txt
    à quelques erreurs de minuscules/majuscules.
    Le souci majeur est la durée de latence qu'il y a entre l'exécution du shellexécute et la création/cloture du fichier "OSName.txt". Il me faut 2 minutes sur ma machine de développement pour clore le fichier. Or, je vérifie que l'OS soit bien un Win Serveur dans les prérequis d'installation. (deux étapes après l'exécution de la ligne de commande, qui est lancée au démarrage de mon exe).
    Si le fichier n'est pas finalisé quand je passe à l'étape suivante de mon fichier d'installation, j'ai un message d'erreur qui apparait me stipulant que le fichier ...\OSname.txt ext utilisé par un autre programme.
    Pour essayer de gagner du temps, j'ai mis des sleep mais ce n'est pas suffisant certaines fois.
    Mes questions sont:
    - existe-t-il une autre méthode plus rapide que celle que j'ai mis en place?
    - sinon, est-il possible de masquer le message d'erreur? (je ne veux pas que le client sache que je créé un fichier OSName.txt^^)
    Merci par avance.

  2. #2
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 695
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 695
    Points : 13 133
    Points
    13 133
    Par défaut
    Inspire-toi de ceci.

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 30
    Points : 26
    Points
    26
    Par défaut
    Merci pour le lien.
    Je viens de tester ce code et ça marche... J'ai du faire n'importe quoi quand j'ai testé le code. Celui-ci est cependant plus complet que celui que j'avais testé.
    Un grand merci ^^

  4. #4
    Modérateur
    Avatar de tourlourou
    Homme Profil pro
    Biologiste ; Progr(amateur)
    Inscrit en
    Mars 2005
    Messages
    3 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Biologiste ; Progr(amateur)

    Informations forums :
    Inscription : Mars 2005
    Messages : 3 858
    Points : 11 301
    Points
    11 301
    Billets dans le blog
    6
    Par défaut
    Même n° de version mineure, oui, mais wProductType distincts...

    Problème persistant en modifiant comme le propose Jipété dans le 2° message de la discussion ?
    Delphi 5 Pro - Delphi 11.3 Alexandria Community Edition - CodeTyphon 6.90 sous Windows 10 ; CT 6.40 sous Ubuntu 18.04 (VM)
    . Ignorer la FAQ Delphi et les Cours et Tutoriels Delphi nuit gravement à notre code !

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 30
    Points : 26
    Points
    26
    Par défaut
    Je viens de tester sur Windows 7 et windows server 2008R2 64bits:
    le ProductType est à 0 pour Windows 7 et pour windows server 2008R2.
    Je ne peux donc pas distinguer les 2 OS... en appliquant les modifications proposées dans la discussion dont le lien est ci dessus.

  6. #6
    Membre chevronné

    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Août 2002
    Messages
    1 288
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Août 2002
    Messages : 1 288
    Points : 1 936
    Points
    1 936
    Par défaut
    Le lien donné par Andnotor a changé. Reessaie, cela fonctionne bien pour Windows Seven.
    Delphi 7/XE2/XE3
    C#
    Oracle 9i à 12c
    SQL Server 2008 à 2014

  7. #7
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 695
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 695
    Points : 13 133
    Points
    13 133
    Par défaut
    Citation Envoyé par sylsi38 Voir le message
    le ProductType est à 0 pour Windows 7 et pour windows server 2008R2.
    C'est pourtant bien ainsi que sont définies les différentes versions.

    Tu ne ferais pas tourner ton application en Mode Compatible Seven par hasard ?

  8. #8
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 30
    Points : 26
    Points
    26
    Par défaut
    J'ai testé le code sur une VM Windows Serveur 2008R2 64 et sur des pc windows7 32 et 64 bits.
    Pour Windows 7, ça m'affiche que je suis sur un Windows Serveur 2008R2...


    Par contre, je ne comprends pas :
    Mode Compatible Seven
    . Je sais que l'on peut faire tourner des logiciels sous 7 en mode compatible.
    Je suis en train de développer mon programme d'installation avec Delphi XE, installé sous un XP pro SP3. Est-ce que le problème viendrait de là... J'en perds mon latin (même si je ne le parle pas mouarf

  9. #9
    Modérateur
    Avatar de tourlourou
    Homme Profil pro
    Biologiste ; Progr(amateur)
    Inscrit en
    Mars 2005
    Messages
    3 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Biologiste ; Progr(amateur)

    Informations forums :
    Inscription : Mars 2005
    Messages : 3 858
    Points : 11 301
    Points
    11 301
    Billets dans le blog
    6
    Par défaut
    Peux-tu poster ton code s'il te plait ?
    Delphi 5 Pro - Delphi 11.3 Alexandria Community Edition - CodeTyphon 6.90 sous Windows 10 ; CT 6.40 sous Ubuntu 18.04 (VM)
    . Ignorer la FAQ Delphi et les Cours et Tutoriels Delphi nuit gravement à notre code !

  10. #10
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 30
    Points : 26
    Points
    26
    Par défaut
    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
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
     
    function GetWindowsVersion: string;
    type
      TGNSI = procedure(var lpSystemInfo: TSystemInfo); stdcall;
      TGPI = function(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion,
        dwSpMinorVersion: DWORD; var pdwReturnedProductType: DWORD): BOOL; stdcall;
     
      _OSVERSIONINFOEX = record
        dwOSVersionInfoSize: DWORD;
        dwMajorVersion: DWORD;
        dwMinorVersion: DWORD;
        dwBuildNumber: DWORD;
        dwPlatformId: DWORD;
        szCSDVersion: array [0 .. 127] of AnsiChar;
        wServicePackMajor: WORD;
        wServicePackMinor: WORD;
        wSuiteMask: WORD;
        wProductType: BYTE;
        wReserved: BYTE;
      end;
     
    const
      // wSuiteMask
      VER_SUITE_SMALLBUSINESS = $1;
      VER_SUITE_ENTERPRISE = $2;
      VER_SUITE_BACKOFFICE = $4;
      VER_SUITE_COMMUNICATIONS = $8;
      VER_SUITE_TERMINAL = $10;
      VER_SUITE_SMALLBUSINESS_RESTRICTED = $20;
      VER_SUITE_EMBEDDEDNT = $40;
      VER_SUITE_DATACENTER = $80;
      VER_SUITE_SINGLEUSERTS = $100;
      VER_SUITE_PERSONAL = $200;
      VER_SUITE_BLADE = $400;
      VER_SUITE_WH_SERVER = $800;
      VER_SUITE_STORAGE_SERVER = $2000;
      VER_SUITE_COMPUTE_SERVER = $4000;
      // wProductType
      VER_NT_WORKSTATION = $1;
      VER_NT_DOMAIN_CONTROLLER = $2;
      VER_NT_SERVER = $3;
     
      PRODUCT_BUSINESS = $6; // Business
      PRODUCT_BUSINESS_N = $10; // Business N
      PRODUCT_CLUSTER_SERVER = $12; // HPC Edition
      PRODUCT_DATACENTER_SERVER = $8; // Server Datacenter (full installation)
      PRODUCT_DATACENTER_SERVER_CORE = $C; // Server Datacenter (core installation)
      PRODUCT_DATACENTER_SERVER_CORE_V = $27;
      // Server Datacenter without Hyper-V (core installation)
      PRODUCT_DATACENTER_SERVER_V = $25;
      // Server Datacenter without Hyper-V (full installation)
      PRODUCT_ENTERPRISE = $4; // Enterprise
      PRODUCT_ENTERPRISE_N = $1B; // Enterprise N
      PRODUCT_ENTERPRISE_SERVER = $A; // Server Enterprise (full installation)
      PRODUCT_ENTERPRISE_SERVER_CORE = $E; // Server Enterprise (core installation)
      PRODUCT_ENTERPRISE_SERVER_CORE_V = $29;
      // Server Enterprise without Hyper-V (core installation)
      PRODUCT_ENTERPRISE_SERVER_IA64 = $F;
      // Server Enterprise for Itanium-based Systems
      PRODUCT_ENTERPRISE_SERVER_V = $26;
      // Server Enterprise without Hyper-V (full installation)
      PRODUCT_HOME_BASIC = $2; // Home Basic
      PRODUCT_HOME_BASIC_N = $5; // Home Basic N
      PRODUCT_HOME_PREMIUM = $3; // Home Premium
      PRODUCT_HOME_PREMIUM_N = $1A; // Home Premium N
      PRODUCT_HYPERV = $2A; // Server Hyper-V
      PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT = $1E;
      // Windows Essential Business Server Management Server
      PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING = $20;
      // Windows Essential Business Server Messaging Server
      PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY = $1F;
      // Windows Essential Business Server Security Server
      PRODUCT_SERVER_FOR_SMALLBUSINESS = $18;
      // Windows Server 2008 for Windows Essential Server Solutions
      PRODUCT_SERVER_FOR_SMALLBUSINESS_V = $23;
      // Windows Server 2008 without Hyper-V for Windows Essential Server Solutions
      PRODUCT_SMALLBUSINESS_SERVER = $9; // Windows Small Business Server
      PRODUCT_SMALLBUSINESS_SERVER_PREMIUM = $19;
      PRODUCT_STANDARD_SERVER = $7; // Server Standard (full installation)
      PRODUCT_STANDARD_SERVER_CORE = $D; // Server Standard (core installation)
      PRODUCT_STANDARD_SERVER_CORE_V = $28;
      // Server Standard without Hyper-V (core installation)
      PRODUCT_STANDARD_SERVER_V = $24;
      // Server Standard without Hyper-V (full installation)
      PRODUCT_STARTER = $B; // Starter
      PRODUCT_STORAGE_ENTERPRISE_SERVER = $17; // Storage Server Enterprise
      PRODUCT_STORAGE_EXPRESS_SERVER = $14; // Storage Server Express
      PRODUCT_STORAGE_STANDARD_SERVER = $15; // Storage Server Standard
      PRODUCT_STORAGE_WORKGROUP_SERVER = $16; // Storage Server Workgroup
      PRODUCT_UNDEFINED = $0; // An unknown product
      PRODUCT_ULTIMATE = $1; // Ultimate
      PRODUCT_ULTIMATE_N = $1C; // Ultimate N
      PRODUCT_WEB_SERVER = $11; // Web Server (full installation)
      PRODUCT_WEB_SERVER_CORE = $1D; // Web Server (core installation)
     
      SM_SERVERR2 = 89;
      PROCESSOR_ARCHITECTURE_INTEL = 0;
      PROCESSOR_ARCHITECTURE_IA64 = 6;
      PROCESSOR_ARCHITECTURE_AMD64 = 9;
     
      BUFSIZE = 80;
    var
      OSVERSIONINFOEX: _OSVERSIONINFOEX;
      OSVERSIONINFO: _OSVERSIONINFO absolute OSVERSIONINFOEX;
      si: SYSTEM_INFO;
      pGNSI: TGNSI;
      pGPI: TGPI;
      bOsVersionInfoEx: Boolean;
      hdlKey: HKEY;
      lRet: LONGINT;
      szProductType: array [0 .. Pred(BUFSIZE)] of Char;
      dwBufLen, dwType: DWORD;
    begin
      Result := '';
      // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
      // If that fails, try using the OSVERSIONINFO structure.
      ZeroMemory(@si, sizeof(SYSTEM_INFO));
      ZeroMemory(@OSVERSIONINFO, sizeof(_OSVERSIONINFOEX));
      OSVERSIONINFO.dwOSVersionInfoSize := sizeof(_OSVERSIONINFOEX);
      bOsVersionInfoEx := GetVersionEx(OSVERSIONINFO);
      if not bOsVersionInfoEx then
      begin
        OSVERSIONINFO.dwOSVersionInfoSize := sizeof(_OSVERSIONINFO);
        if not GetVersionEx(OSVERSIONINFO) then
          Exit;
      end;
     
      // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.
      pGNSI := GetProcAddress(GetModuleHandle('kernel32.dll'),
        'GetNativeSystemInfo');
      if Assigned(pGNSI) then
        pGNSI(si)
      else
        GetSystemInfo(si);
     
      case OSVERSIONINFO.dwPlatformId of
        // Test for the Windows NT product family.
        VER_PLATFORM_WIN32_NT:
          begin
            // Test for the specific product family.
            Result := 'Unknown Windows';
            if (OSVERSIONINFO.dwMajorVersion = 6) then
            begin
              case OSVERSIONINFO.dwMinorVersion of
                0:
                  if (OSVERSIONINFOEX.wProductType = VER_NT_WORKSTATION) then
                    Result := 'Windows Vista'
                  else
                    Result := 'Windows Server 2008';
                1:
                  begin
                    if (OSVERSIONINFOEX.wProductType = VER_NT_WORKSTATION) then
                      Result := 'Windows Seven'
                    else
                      Result := 'Windows Server 2008 R2';
                  end;
              end;
              pGPI := GetProcAddress(GetModuleHandle('kernel32.dll'),
                'GetProductInfo');
              pGPI(6, 0, 0, 0, dwType);
     
              case dwType of
                PRODUCT_ULTIMATE:
                  Result := Result + ' Ultimate Edition';
                PRODUCT_HOME_PREMIUM:
                  Result := Result + ' Home Premium Edition';
                PRODUCT_HOME_BASIC:
                  Result := Result + ' Home Basic Edition';
                PRODUCT_ENTERPRISE:
                  Result := Result + ' Enterprise Edition';
                PRODUCT_BUSINESS:
                  Result := Result + ' Business Edition';
                PRODUCT_STARTER:
                  Result := Result + ' Starter Edition';
                PRODUCT_CLUSTER_SERVER:
                  Result := Result + ' Cluster Server Edition';
                PRODUCT_DATACENTER_SERVER:
                  Result := Result + ' Datacenter Edition';
                PRODUCT_DATACENTER_SERVER_CORE:
                  Result := Result + ' Datacenter Edition (core installation)';
                PRODUCT_ENTERPRISE_SERVER:
                  Result := Result + ' Enterprise Edition';
                PRODUCT_ENTERPRISE_SERVER_CORE:
                  Result := Result + ' Enterprise Edition (core installation)';
                PRODUCT_ENTERPRISE_SERVER_IA64:
                  Result := Result +
                    ' Enterprise Edition for Itanium-based Systems';
                PRODUCT_SMALLBUSINESS_SERVER:
                  Result := Result + ' Small Business Server';
                PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
                  Result := Result + ' Small Business Server Premium Edition';
                PRODUCT_STANDARD_SERVER:
                  Result := Result + ' Standard Edition';
                PRODUCT_STANDARD_SERVER_CORE:
                  Result := Result + ' Standard Edition (core installation)';
                PRODUCT_WEB_SERVER:
                  Result := Result + ' Web Server Edition';
              end;
     
              if (si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64) then
                Result := Result + ', 64-bit'
              else if (si.wProcessorArchitecture =
                PROCESSOR_ARCHITECTURE_INTEL) then
                Result := Result + ', 32-bit';
            end;
            if (OSVERSIONINFO.dwMajorVersion = 5) and
              (OSVERSIONINFO.dwMinorVersion = 2) then
            begin
              if (GetSystemMetrics(SM_SERVERR2) <> 0) then
                Result := 'Windows Server 2003 R2, '
              else if (OSVERSIONINFOEX.wSuiteMask = VER_SUITE_STORAGE_SERVER) then
                Result := 'Windows Storage Server 2003'
              else if (OSVERSIONINFOEX.wSuiteMask = VER_SUITE_WH_SERVER) then
                Result := 'Windows Home Server'
              else if (OSVERSIONINFOEX.wProductType = VER_NT_WORKSTATION) and
                (si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64) then
                Result := 'Windows XP Professional x64 Edition'
              else
                Result := 'Windows Server 2003, ';
     
              // Test for the server type.
              if (OSVERSIONINFOEX.wProductType <> VER_NT_WORKSTATION) then
              begin
                if (si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_IA64) then
                begin
                  if (OSVERSIONINFOEX.wSuiteMask and VER_SUITE_DATACENTER) <> 0 then
                    Result := Result +
                      ' Datacenter Edition for Itanium-based Systems'
                  else if (OSVERSIONINFOEX.wSuiteMask and VER_SUITE_ENTERPRISE)
                    <> 0 then
                    Result := Result +
                      ' Enterprise Edition for Itanium-based Systems';
                end
                else if (si.wProcessorArchitecture =
                  PROCESSOR_ARCHITECTURE_AMD64) then
                begin
                  if (OSVERSIONINFOEX.wSuiteMask and VER_SUITE_DATACENTER) <> 0 then
                    Result := Result + ' Datacenter x64 Edition'
                  else if (OSVERSIONINFOEX.wSuiteMask and VER_SUITE_ENTERPRISE)
                    <> 0 then
                    Result := Result + ' Enterprise x64 Edition'
                  else
                    Result := Result + ' Standard x64 Edition';
                end
                else
                begin
                  if (OSVERSIONINFOEX.wSuiteMask and VER_SUITE_COMPUTE_SERVER)
                    <> 0 then
                    Result := Result + ' Compute Cluster Edition'
                  else if (OSVERSIONINFOEX.wSuiteMask and VER_SUITE_DATACENTER)
                    <> 0 then
                    Result := Result + ' Datacenter Edition'
                  else if (OSVERSIONINFOEX.wSuiteMask and VER_SUITE_ENTERPRISE)
                    <> 0 then
                    Result := Result + ' Enterprise Edition'
                  else if (OSVERSIONINFOEX.wSuiteMask and VER_SUITE_BLADE) <> 0 then
                    Result := Result + ' Web Edition'
                  else
                    Result := Result + ' Standard Edition';
                end
              end;
            end;
            if (OSVERSIONINFO.dwMajorVersion = 5) and
              (OSVERSIONINFO.dwMinorVersion = 1) then
            begin
              Result := 'Windows XP';
              if (OSVERSIONINFOEX.wSuiteMask and VER_SUITE_PERSONAL) <> 0 then
                Result := Result + ' Home Edition'
              else
                Result := Result + ' Professional';
            end;
     
            if (OSVERSIONINFO.dwMajorVersion = 5) and
              (OSVERSIONINFO.dwMinorVersion = 0) then
            begin
              Result := 'Windows 2000';
     
              if (OSVERSIONINFOEX.wProductType = VER_NT_WORKSTATION) then
                Result := Result + ' Professional'
              else
              begin
                if (OSVERSIONINFOEX.wSuiteMask and VER_SUITE_DATACENTER) <> 0 then
                  Result := Result + ' Datacenter Server'
                else if (OSVERSIONINFOEX.wSuiteMask and VER_SUITE_ENTERPRISE)
                  <> 0 then
                  Result := Result + ' Advanced Server'
                else
                  Result := Result + ' Server';
              end;
            end;
     
            if (OSVERSIONINFO.dwMajorVersion <= 4) then
            begin
              Result := 'Windows NT';
              // Test for specific product on Windows NT 4.0 SP6 and later.
              if bOsVersionInfoEx then
              begin
                // Test for the workstation type.
                if (OSVERSIONINFOEX.wProductType = VER_NT_WORKSTATION) and
                  (si.wProcessorArchitecture <> PROCESSOR_ARCHITECTURE_AMD64) then
                  Result := Result + ' Workstation 4.0'
                  // Test for the server type.
                else if (OSVERSIONINFOEX.wProductType = VER_NT_SERVER) or
                  (OSVERSIONINFOEX.wProductType = VER_NT_DOMAIN_CONTROLLER) then
                begin
                  if BOOL(OSVERSIONINFOEX.wSuiteMask and VER_SUITE_ENTERPRISE) then
                    Result := Result + ' Server 4.0, Enterprise Edition'
                  else
                    Result := Result + ' Server';
                end
              end
              else
              begin // Test for specific product on Windows NT 4.0 SP5 and earlier
                dwBufLen := BUFSIZE;
                lRet := RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                  'SYSTEM\CurrentControlSet\Control\ProductOptions', 0,
                  KEY_QUERY_VALUE, hdlKey);
                if (lRet <> ERROR_SUCCESS) then
                  Exit;
                lRet := RegQueryValueEx(hdlKey, 'ProductType', nil, nil,
                  @szProductType[1], @dwBufLen);
                if ((lRet <> ERROR_SUCCESS) or (dwBufLen > BUFSIZE)) then
                  Exit;
                RegCloseKey(hdlKey);
                if (lstrcmpi('WINNT', szProductType) = 0) then
                  Result := Result + ' Workstation';
                if (lstrcmpi('LANMANNT', szProductType) = 0) then
                  Result := Result + ' Server';
                if (lstrcmpi('SERVERNT', szProductType) = 0) then
                  Result := Result + ' Advanced Server';
                Result := Result + Format(' %d.%d', [OSVERSIONINFO.dwMajorVersion,
                  OSVERSIONINFO.dwMinorVersion]);
              end;
            end;
            // Display service pack (if any) and build number.
            if (OSVERSIONINFO.dwMajorVersion = 4) and
              (lstrcmpi(OSVERSIONINFO.szCSDVersion, 'Service Pack 6') = 0) then
            begin
              // Test for SP6 versus SP6a.
              lRet := RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix\Q246009', 0,
                KEY_QUERY_VALUE, hdlKey);
              if (lRet = ERROR_SUCCESS) then
                Result := Result + Format(' Service Pack 6a (Build %d)',
                  [OSVERSIONINFO.dwBuildNumber and $FFFF])
              else // Windows NT 4.0 prior to SP6a
                Result := Result + Format(' %s (Build %d)',
                  [OSVERSIONINFO.szCSDVersion,
                  OSVERSIONINFO.dwBuildNumber and $FFFF]);
              RegCloseKey(hdlKey);
            end
            else
            begin
              Result := Result + Format(' %s (Build %d)',
                [OSVERSIONINFO.szCSDVersion,
                OSVERSIONINFO.dwBuildNumber and $FFFF]);
            end;
          end;
        // Test for the Windows 95 product family.
        VER_PLATFORM_WIN32_WINDOWS:
          begin
            if (OSVERSIONINFO.dwMajorVersion = 4) and
              (OSVERSIONINFO.dwMinorVersion = 0) then
            begin
              Result := 'Windows 95';
              if (OSVERSIONINFO.szCSDVersion[1] = 'C') or
                (OSVERSIONINFO.szCSDVersion[1] = 'B') then
                Result := Result + ' OSR2';
            end;
            if (OSVERSIONINFO.dwMajorVersion = 4) and
              (OSVERSIONINFO.dwMinorVersion = 10) then
            begin
              Result := 'Windows 98';
              if (OSVERSIONINFO.szCSDVersion[1] = 'A') then
                Result := Result + ' SE';
            end;
            if (OSVERSIONINFO.dwMajorVersion = 4) and
              (OSVERSIONINFO.dwMinorVersion = 90) then
              Result := 'Windows ME';
          end;
        VER_PLATFORM_WIN32s:
          Result := 'Windows Win32s';
      end;
    end;
    Bonjour,

    je poste ma fonction de vérification de l'OS. Elle est appelée lors de la création de la frame d'installation.

  11. #11
    Modérateur
    Avatar de tourlourou
    Homme Profil pro
    Biologiste ; Progr(amateur)
    Inscrit en
    Mars 2005
    Messages
    3 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Biologiste ; Progr(amateur)

    Informations forums :
    Inscription : Mars 2005
    Messages : 3 858
    Points : 11 301
    Points
    11 301
    Billets dans le blog
    6
    Par défaut
    Ce code me répond correctement Seven sur mon PC 64 bits...

    Que vaut bOsVersionInfoEx ?
    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
            if (OSVERSIONINFO.dwMajorVersion = 6) then
            begin
              case OSVERSIONINFO.dwMinorVersion of
                0:
                  if (OSVERSIONINFOEX.wProductType = VER_NT_WORKSTATION) then
                    Result := 'Windows Vista'
                  else
                    Result := 'Windows Server 2008';
                1:
                  begin
                    if (OSVERSIONINFOEX.wProductType = VER_NT_WORKSTATION) then
                      Result := 'Windows Seven'
                    else
                      Result := 'Windows Server 2008 R2';
                  end;
              end;
    Car ce code teste systématiquement OSVERSIONINFOEX.wProductType : si bOsVersionInfoEx est FALSE, ce champ a été initialisé à 0, qui est bien différent de VER_NT_WORKSTATION et renverrait WS2008R2 au lieu de Seven.

    Mais pourquoi diantre Seven refuserait-il de remplir OSVERSIONINFOEX au GetVersionEx(OSVERSIONINFO) ?

    Peut-être une taille inadéquate, liée au fait que le record n'a pas été déclaré packed ?
    Delphi 5 Pro - Delphi 11.3 Alexandria Community Edition - CodeTyphon 6.90 sous Windows 10 ; CT 6.40 sous Ubuntu 18.04 (VM)
    . Ignorer la FAQ Delphi et les Cours et Tutoriels Delphi nuit gravement à notre code !

  12. #12
    Expert éminent sénior
    Avatar de Jipété
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    10 730
    Détails du profil
    Informations personnelles :
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 10 730
    Points : 15 132
    Points
    15 132
    Par défaut
    Citation Envoyé par tourlourou Voir le message
    (...) Peut-être une taille inadéquate, liée au fait que le record n'a pas été déclaré packed ?
    Salut Yves, salut à tous,

    Sans rajouter "Packed", le code de Sylsi38 (qui est celui qui tourne un peu partout sur le Web) me retourne
    Windows Seven Business Edition, 32-bit Service Pack 1 (Build 7601)
    Pareil en rajoutant "Packed".

    Testé sous 7/32 avec Lazarus 0.9, sans rien changer au code de la fonction.

    Si ça peut aider à faire avancer le bazar...
    Il a à vivre sa vie comme ça et il est mûr sur ce mur se creusant la tête : peutêtre qu'il peut être sûr, etc.
    Oui, je milite pour l'orthographe et le respect du trait d'union à l'impératif.
    Après avoir posté, relisez-vous ! Et en cas d'erreur ou d'oubli, il existe un bouton « Modifier », à utiliser sans modération
    On a des lois pour protéger les remboursements aux faiseurs d’argent. On n’en a pas pour empêcher un être humain de mourir de misère.
    Mes 2 cts,
    --
    jp

  13. #13
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 30
    Points : 26
    Points
    26
    Par défaut
    Bonjour,

    j'ai testé sur le pc d'un collègue. J'obtiens le même bug.
    Quand je fais un
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    ShowMessage('productType : '+inttostr(OSVERSIONINFOEX.wProductType));
    J'obtiens "productType : 0".
    Je n'arrive pas à obtenir l'info du productType...

  14. #14
    Expert éminent sénior
    Avatar de Jipété
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    10 730
    Détails du profil
    Informations personnelles :
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 10 730
    Points : 15 132
    Points
    15 132
    Par défaut
    Citation Envoyé par sylsi38 Voir le message
    (...) Je n'arrive pas à obtenir l'info du productType...
    Est-ce que tu as les " droits " ? Es-tu Admin du poste quand tu fais tourner le test ?
    Il a à vivre sa vie comme ça et il est mûr sur ce mur se creusant la tête : peutêtre qu'il peut être sûr, etc.
    Oui, je milite pour l'orthographe et le respect du trait d'union à l'impératif.
    Après avoir posté, relisez-vous ! Et en cas d'erreur ou d'oubli, il existe un bouton « Modifier », à utiliser sans modération
    On a des lois pour protéger les remboursements aux faiseurs d’argent. On n’en a pas pour empêcher un être humain de mourir de misère.
    Mes 2 cts,
    --
    jp

  15. #15
    Modérateur
    Avatar de tourlourou
    Homme Profil pro
    Biologiste ; Progr(amateur)
    Inscrit en
    Mars 2005
    Messages
    3 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Biologiste ; Progr(amateur)

    Informations forums :
    Inscription : Mars 2005
    Messages : 3 858
    Points : 11 301
    Points
    11 301
    Billets dans le blog
    6
    Par défaut
    Et que vaut bOsVersionInfoEx sur les postes où il se plante ? S'il est FALSE, on n'a pas pu récupérer le type de produit.

    Or rappelons que les valeurs possibles de wProductType selon la msdn sont 1, 2 et 3, et que 0 est la valeur d'initialisation...

    Vérifie les versions de kernel32.dll entre les postes qui passent et les autres.

    @Jean-Pierre : Bonjour ! Ca passait chez toi sous Lazarus sans rien changer ? J'ai été contraint de faire un truc du style pGNSI := TGNSI( GetProcAddress(GetModuleHandle('kernel32.dll'), 'GetNativeSystemInfo') );
    Delphi 5 Pro - Delphi 11.3 Alexandria Community Edition - CodeTyphon 6.90 sous Windows 10 ; CT 6.40 sous Ubuntu 18.04 (VM)
    . Ignorer la FAQ Delphi et les Cours et Tutoriels Delphi nuit gravement à notre code !

  16. #16
    Expert éminent sénior
    Avatar de Jipété
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    10 730
    Détails du profil
    Informations personnelles :
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 10 730
    Points : 15 132
    Points
    15 132
    Par défaut
    Citation Envoyé par tourlourou Voir le message
    (...) @Jean-Pierre : Bonjour ! Ca passait chez toi sous Lazarus sans rien changer ? J'ai été contraint de faire un truc du style pGNSI := TGNSI( GetProcAddress(GetModuleHandle('kernel32.dll'), 'GetNativeSystemInfo') );
    Je ne me suis pas embêté, j'ai copié/collé la fonction dans un projet ouvert (mais qui venait de Delphi) et ça a roulé tip-top.
    Mais effectivement, quand j'ai collé la fonction dans un autre projet natif Laz, ça a coincé comme pour toi...
    J'ai comparé les "uses" et j'ai fait ça là où ça ne passait pas :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    unit Unit1; 
     
    //{$mode objfpc}{$H+} // mode Laz natif
    {$IFDEF FPC}
      {$MODE Delphi}
    {$ENDIF}
     
    interface
    Désolé pour le HS, sylsi38.

    Cependant, les pistes de recherche d'Yves sont à explorer...
    Il a à vivre sa vie comme ça et il est mûr sur ce mur se creusant la tête : peutêtre qu'il peut être sûr, etc.
    Oui, je milite pour l'orthographe et le respect du trait d'union à l'impératif.
    Après avoir posté, relisez-vous ! Et en cas d'erreur ou d'oubli, il existe un bouton « Modifier », à utiliser sans modération
    On a des lois pour protéger les remboursements aux faiseurs d’argent. On n’en a pas pour empêcher un être humain de mourir de misère.
    Mes 2 cts,
    --
    jp

  17. #17
    Membre chevronné

    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Août 2002
    Messages
    1 288
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Août 2002
    Messages : 1 288
    Points : 1 936
    Points
    1 936
    Par défaut
    Utilise GetVersionExA au lieu de GetVersionEx (qui correspond à GetVersionExW sur un delphi unicode), étant donné que ta structure est ANSI.

    Je reproduis ton problème sur un Vista, il me dit que c'est un windows server 2008 si j'utilise GetVersionExW au lieu de GetVersionExA.

    Il n'y a pas besoin de droits administrateur.
    Delphi 7/XE2/XE3
    C#
    Oracle 9i à 12c
    SQL Server 2008 à 2014

  18. #18
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    30
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 30
    Points : 26
    Points
    26
    Par défaut
    Je ne comprends pas ce qui vient de se passer. J'ai modifier le code, créé un case pour traiter les différents cas pour les windows 7 et windows server 2008R2.
    J'ai supprimé les codes pour les versions antérieures à XP et là, à ma grande surprise, je trouve bOsVersionInfo à true et je trouve le bon OS (Windows 7 pour mon pc et celui de mon collègue...).
    Je vous remercie pour vos pistes.

    Pour information, je suis "admin" de mon pc et mon collègue non et on obtient le même résultat. Il ne faut donc pas être admin de son pc pour lancer ce code.

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

Discussions similaires

  1. Réponses: 21
    Dernier message: 18/08/2005, 16h06
  2. Code machine
    Par Willand dans le forum Assembleur
    Réponses: 2
    Dernier message: 20/01/2003, 18h44
  3. Lancer un programme, mais sur une autre machine
    Par GOUGOU1 dans le forum Réseau
    Réponses: 12
    Dernier message: 08/12/2002, 20h36
  4. Réponses: 4
    Dernier message: 10/09/2002, 17h09
  5. Comment définir le type matrice ?
    Par charly dans le forum Langage
    Réponses: 7
    Dernier message: 15/06/2002, 21h01

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