Votre question

Récupere numéro build windows C++

Tags :
  • Programme
  • Programmation
Dernière réponse : dans Programmation
a b L Programmation
3 Novembre 2009 23:55:20

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 ^^

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


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

  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

Autres pages sur : recupere numero build windows

4 Novembre 2009 07:31:08

salut,

http://msdn.microsoft.com/en-us/library/ms724451(VS.85).aspx


GetVersion (et fonctions suivantes ...)


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

http://msdn.microsoft.com/en-us/library/ms724834(VS.85).aspx


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

Merci , je vais analysée tous ça !
m
0
l
25 Novembre 2009 11:42:50

On n'appelle jamais system() en C !! Quelle horreur !
Surtout sous windows (interdit, cf MSDN)
cf Shtudown apis instead...
m
0
l
Tom's guide dans le monde
  • Allemagne
  • Italie
  • Irlande
  • Royaume Uni
  • Etats Unis
Suivre Tom's Guide
Inscrivez-vous à la Newsletter
  • ajouter à twitter
  • ajouter à facebook
  • ajouter un flux RSS