Tom's Guide > Forum > Programmation > Récupere numéro build windows C++

Récupere numéro build windows C++

Forum Programmation : Récupere numéro build windows C++

TomsGuide.com : 800 000 inscrits répondent à toutes vos questions high-tech et informatique. Pour obtenir de l'aide, inscrivez-vous gratuitement !
Mot :    Pseudo :           
 

Bonjours a tous , alors voila je voudrais améliorais mon programme c++
qui ne marche plus sous les version vista et seven ...

donc voila la ligne qui fais tous ^^

Code :
  1. system("%windir%\\system32\\shutdown.exe -r -t120" );



le truc c'est que sous vista et seven cette ligne ce transforme en

Code :
  1. system("%windir%\\system32\\shutdown.exe /r /t120" );



je voudrais savoir comment récupérer le numéro de la build de Windows ... comme sa
j'ai juste un if a rajouter ^^ ( en sachant xp < 600 vista > 6000 , seven > 7000 )

ou alors modifier la ligne pour forcer le système a redémarrer

------------------------------ XD --> peut aussi se dessiner --> XP
Microsoft se fout-il pas ne notre tete avec son XP ???
Liens sponsorisés
Inscrivez-vous ou connectez-vous pour masquer ceci.

salut,

 

http://msdn.microsoft.com/en-us/li [...] S.85).aspx

 


GetVersion (et fonctions suivantes ...)

 


OSVERSIONINFO osv;
osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osv);

 

http://msdn.microsoft.com/en-us/li [...] S.85).aspx

 


Code :
  1. typedef struct _OSVERSIONINFO {
  2.   DWORD dwOSVersionInfoSize;
  3.   DWORD dwMajorVersion;
  4.   DWORD dwMinorVersion;
  5.   DWORD dwBuildNumber;
  6.   DWORD dwPlatformId;
  7.   TCHAR szCSDVersion[128];
  8. }OSVERSIONINFO;
 


Sur cette page ( http://msdn.microsoft.com/en-us/li [...] S.85).aspx ), tu auras le détail des versions mineures/majeures XP/vista/2008/7 [....]

 

en espérant t'avoir aidé..

  


ET un joli copié/collé du code source exemple donné par MSDN:

Code :
  1. #include <windows.h>
  2. #include <tchar.h>
  3. #include <stdio.h>
  4. #include <strsafe.h>
  5. #pragma comment(lib, "User32.lib" )
  6. #define BUFSIZE 256
  7. typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
  8. typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
  9. BOOL GetOSDisplayString( LPTSTR pszOS)
  10. {
  11.   OSVERSIONINFOEX osvi;
  12.   SYSTEM_INFO si;
  13.   PGNSI pGNSI;
  14.   PGPI pGPI;
  15.   BOOL bOsVersionInfoEx;
  16.   DWORD dwType;
  17.   ZeroMemory(&si, sizeof(SYSTEM_INFO));
  18.   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
  19.   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  20.   if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
  21.       return 1;
  22.   // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.
  23.   pGNSI = (PGNSI) GetProcAddress(
  24.       GetModuleHandle(TEXT("kernel32.dll" )),
  25.       "GetNativeSystemInfo" );
  26.   if(NULL != pGNSI)
  27.       pGNSI(&si);
  28.   else GetSystemInfo(&si);
  29.   if ( VER_PLATFORM_WIN32_NT==osvi.dwPlatformId &&
  30.         osvi.dwMajorVersion > 4 )
  31.   {
  32.       StringCchCopy(pszOS, BUFSIZE, TEXT("Microsoft " ));
  33.       // Test for the specific product.
  34.       if ( osvi.dwMajorVersion == 6 )
  35.       {
  36.         if( osvi.dwMinorVersion == 0 )
  37.         {
  38.             if( osvi.wProductType == VER_NT_WORKSTATION )
  39.                 StringCchCat(pszOS, BUFSIZE, TEXT("Windows Vista " ));
  40.             else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2008 " ));
  41.         }
  42.         if ( osvi.dwMinorVersion == 1 )
  43.         {
  44.             if( osvi.wProductType == VER_NT_WORKSTATION )
  45.                 StringCchCat(pszOS, BUFSIZE, TEXT("Windows 7 " ));
  46.             else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2008 R2 " ));
  47.         }
  48.        
  49.         pGPI = (PGPI) GetProcAddress(
  50.             GetModuleHandle(TEXT("kernel32.dll" )),
  51.             "GetProductInfo" );
  52.         pGPI( osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType);
  53.         switch( dwType )
  54.         {
  55.             case PRODUCT_ULTIMATE:
  56.               StringCchCat(pszOS, BUFSIZE, TEXT("Ultimate Edition" ));
  57.               break;
  58.             case PRODUCT_HOME_PREMIUM:
  59.               StringCchCat(pszOS, BUFSIZE, TEXT("Home Premium Edition" ));
  60.               break;
  61.             case PRODUCT_HOME_BASIC:
  62.               StringCchCat(pszOS, BUFSIZE, TEXT("Home Basic Edition" ));
  63.               break;
  64.             case PRODUCT_ENTERPRISE:
  65.               StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition" ));
  66.               break;
  67.             case PRODUCT_BUSINESS:
  68.               StringCchCat(pszOS, BUFSIZE, TEXT("Business Edition" ));
  69.               break;
  70.             case PRODUCT_STARTER:
  71.               StringCchCat(pszOS, BUFSIZE, TEXT("Starter Edition" ));
  72.               break;
  73.             case PRODUCT_CLUSTER_SERVER:
  74.               StringCchCat(pszOS, BUFSIZE, TEXT("Cluster Server Edition" ));
  75.               break;
  76.             case PRODUCT_DATACENTER_SERVER:
  77.               StringCchCat(pszOS, BUFSIZE, TEXT("Datacenter Edition" ));
  78.               break;
  79.             case PRODUCT_DATACENTER_SERVER_CORE:
  80.               StringCchCat(pszOS, BUFSIZE, TEXT("Datacenter Edition (core installation)" ));
  81.               break;
  82.             case PRODUCT_ENTERPRISE_SERVER:
  83.               StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition" ));
  84.               break;
  85.             case PRODUCT_ENTERPRISE_SERVER_CORE:
  86.               StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition (core installation)" ));
  87.               break;
  88.             case PRODUCT_ENTERPRISE_SERVER_IA64:
  89.               StringCchCat(pszOS, BUFSIZE, TEXT("Enterprise Edition for Itanium-based Systems" ));
  90.               break;
  91.             case PRODUCT_SMALLBUSINESS_SERVER:
  92.               StringCchCat(pszOS, BUFSIZE, TEXT("Small Business Server" ));
  93.               break;
  94.             case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
  95.               StringCchCat(pszOS, BUFSIZE, TEXT("Small Business Server Premium Edition" ));
  96.               break;
  97.             case PRODUCT_STANDARD_SERVER:
  98.               StringCchCat(pszOS, BUFSIZE, TEXT("Standard Edition" ));
  99.               break;
  100.             case PRODUCT_STANDARD_SERVER_CORE:
  101.               StringCchCat(pszOS, BUFSIZE, TEXT("Standard Edition (core installation)" ));
  102.               break;
  103.             case PRODUCT_WEB_SERVER:
  104.               StringCchCat(pszOS, BUFSIZE, TEXT("Web Server Edition" ));
  105.               break;
  106.         }
  107.       }
  108.       if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
  109.       {
  110.         if( GetSystemMetrics(SM_SERVERR2) )
  111.             StringCchCat(pszOS, BUFSIZE, TEXT( "Windows Server 2003 R2, " ));
  112.         else if ( osvi.wSuiteMask==VER_SUITE_STORAGE_SERVER )
  113.             StringCchCat(pszOS, BUFSIZE, TEXT( "Windows Storage Server 2003" ));
  114.         else if ( osvi.wSuiteMask==VER_SUITE_WH_SERVER )
  115.             StringCchCat(pszOS, BUFSIZE, TEXT( "Windows Home Server" ));
  116.         else if( osvi.wProductType == VER_NT_WORKSTATION &&
  117.                   si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
  118.         {
  119.             StringCchCat(pszOS, BUFSIZE, TEXT( "Windows XP Professional x64 Edition" ));
  120.         }
  121.         else StringCchCat(pszOS, BUFSIZE, TEXT("Windows Server 2003, " ));
  122.         // Test for the server type.
  123.         if ( osvi.wProductType != VER_NT_WORKSTATION )
  124.         {
  125.             if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64 )
  126.             {
  127.                 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
  128.                   StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter Edition for Itanium-based Systems" ));
  129.                 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
  130.                   StringCchCat(pszOS, BUFSIZE, TEXT( "Enterprise Edition for Itanium-based Systems" ));
  131.             }
  132.             else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
  133.             {
  134.                 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
  135.                   StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter x64 Edition" ));
  136.                 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
  137.                   StringCchCat(pszOS, BUFSIZE, TEXT( "Enterprise x64 Edition" ));
  138.                 else StringCchCat(pszOS, BUFSIZE, TEXT( "Standard x64 Edition" ));
  139.             }
  140.             else
  141.             {
  142.                 if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER )
  143.                   StringCchCat(pszOS, BUFSIZE, TEXT( "Compute Cluster Edition" ));
  144.                 else if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
  145.                   StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter Edition" ));
  146.                 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
  147.                   StringCchCat(pszOS, BUFSIZE, TEXT( "Enterprise Edition" ));
  148.                 else if ( osvi.wSuiteMask & VER_SUITE_BLADE )
  149.                   StringCchCat(pszOS, BUFSIZE, TEXT( "Web Edition" ));
  150.                 else StringCchCat(pszOS, BUFSIZE, TEXT( "Standard Edition" ));
  151.             }
  152.         }
  153.       }
  154.       if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
  155.       {
  156.         StringCchCat(pszOS, BUFSIZE, TEXT("Windows XP " ));
  157.         if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
  158.             StringCchCat(pszOS, BUFSIZE, TEXT( "Home Edition" ));
  159.         else StringCchCat(pszOS, BUFSIZE, TEXT( "Professional" ));
  160.       }
  161.       if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
  162.       {
  163.         StringCchCat(pszOS, BUFSIZE, TEXT("Windows 2000 " ));
  164.         if ( osvi.wProductType == VER_NT_WORKSTATION )
  165.         {
  166.             StringCchCat(pszOS, BUFSIZE, TEXT( "Professional" ));
  167.         }
  168.         else
  169.         {
  170.             if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
  171.               StringCchCat(pszOS, BUFSIZE, TEXT( "Datacenter Server" ));
  172.             else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
  173.               StringCchCat(pszOS, BUFSIZE, TEXT( "Advanced Server" ));
  174.             else StringCchCat(pszOS, BUFSIZE, TEXT( "Server" ));
  175.         }
  176.       }
  177.       // Include service pack (if any) and build number.
  178.       if( _tcslen(osvi.szCSDVersion) > 0 )
  179.       {
  180.           StringCchCat(pszOS, BUFSIZE, TEXT(" " ) );
  181.           StringCchCat(pszOS, BUFSIZE, osvi.szCSDVersion);
  182.       }
  183.       TCHAR buf[80];
  184.       StringCchPrintf( buf, 80, TEXT(" (build %d)" ), osvi.dwBuildNumber);
  185.       StringCchCat(pszOS, BUFSIZE, buf);
  186.       if ( osvi.dwMajorVersion >= 6 )
  187.       {
  188.         if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
  189.             StringCchCat(pszOS, BUFSIZE, TEXT( ", 64-bit" ));
  190.         else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL )
  191.             StringCchCat(pszOS, BUFSIZE, TEXT(", 32-bit" ));
  192.       }
  193.      
  194.       return TRUE;
  195.   }
  196.   else
  197.   { 
  198.       printf( "This sample does not support this version of Windows.\n" );
  199.       return FALSE;
  200.   }
  201. }
  202. int __cdecl _tmain()
  203. {
  204.     TCHAR szOS[BUFSIZE];
  205.     if( GetOSDisplayString( szOS ) )
  206.         _tprintf( TEXT("\n%s\n" ), szOS );
  207. }


Message édité par elendilm le 04-11-2009 à 07:40:14
Répondre à elendilm

Merci , je vais analysée tous ça !

------------------------------ XD --> peut aussi se dessiner --> XP
Microsoft se fout-il pas ne notre tete avec son XP ???
Répondre à andrelec1

On n'appelle jamais system() en C !! Quelle horreur !
Surtout sous windows (interdit, cf MSDN)
cf Shtudown apis instead...

Répondre à terryst
Tom's Guide > Forum > Programmation > Récupere numéro build windows C++
Aller à :

Il y a 2225 utilisateurs connus et inconnus. Pour voir la liste des connectés connus, cliquez ici.

Liens