惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
W
WeLiveSecurity
O
OpenAI News
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Webroot Blog
Webroot Blog
Google Online Security Blog
Google Online Security Blog
云风的 BLOG
云风的 BLOG
N
News | PayPal Newsroom
H
Hacker News: Front Page
博客园_首页
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The Last Watchdog
The Last Watchdog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Heimdal Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Schneier on Security
宝玉的分享
宝玉的分享
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
Microsoft Security Blog
Microsoft Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
GbyAI
GbyAI
Cloudbric
Cloudbric
TaoSecurity Blog
TaoSecurity Blog
人人都是产品经理
人人都是产品经理
P
Palo Alto Networks Blog
M
MIT News - Artificial intelligence
G
GRAHAM CLULEY
C
Check Point Blog
Apple Machine Learning Research
Apple Machine Learning Research
Last Week in AI
Last Week in AI
T
Troy Hunt's Blog
L
Lohrmann on Cybersecurity
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
量子位
博客园 - 聂微东
S
Securelist
博客园 - 三生石上(FineUI控件)
F
Full Disclosure
G
Google Developers Blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
AI
AI
PCI Perspectives
PCI Perspectives

博客园 - 飞天名猪

django 定制管理页面外观 模板文件不生效的解决方法 新手上路,django学习笔记(1) 环境部署 Windows7系统命令总结 VC 编程ANSI环境下读写Unicode文件(转载) ICE3.1.1 开发中遇到的问题(四) 发布9个腾讯微博的邀请码 [转载]vc6转2008的一些实践经验 - 飞天名猪 - 博客园 IcePatch2+IceGrid部署的解决方案 ICE 开发中遇到的问题(三) Ice开发中遇到的问题(二) ICE开发中遇到的问题 (一) - 飞天名猪 - 博客园 使用ICE遇到的编译问题 dbf文件结构 浏览器插件-- Browser Helper Object(BHO) 四 浏览器插件-- Browser Helper Object(BHO) 三 浏览器插件-- Browser Helper Object(BHO) 二 浏览器插件-- Browser Helper Object(BHO) 一 window程序自启动的几种方法(四) windows程序自启动的几种方法(三)系统配置文件
判断操作系统的类型
飞天名猪 · 2009-03-23 · via 博客园 - 飞天名猪

#include <windows.h>
#include <tchar.h>
#include <stdio.h>

#define BUFSIZE 80

typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);

int __cdecl _tmain()
{
   OSVERSIONINFOEX osvi;
   SYSTEM_INFO si;
   PGNSI pGNSI;
   BOOL bOsVersionInfoEx;

   ZeroMemory(&si, sizeof(SYSTEM_INFO));
   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

   // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
   // If that fails, try using the OSVERSIONINFO structure.

   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

   if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
   {
      osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
      if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
         return FALSE;
   }

   // Call GetNativeSystemInfo if supported
   // or GetSystemInfo otherwise.

   pGNSI = (PGNSI) GetProcAddress(
      GetModuleHandle(TEXT("kernel32.dll")),
      "GetNativeSystemInfo");
   if(NULL != pGNSI)
      pGNSI(&si);
   else GetSystemInfo(&si);

   switch (osvi.dwPlatformId)
   {
      // Test for the Windows NT product family.

      case VER_PLATFORM_WIN32_NT:

      // Test for the specific product.

      if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 )
      {
         if( osvi.wProductType == VER_NT_WORKSTATION )
             printf ("Windows Vista ");
         else printf ("Windows Server \"Longhorn\" " );
      }

      if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
      {
         if( GetSystemMetrics(SM_SERVERR2) )
            printf( "Microsoft Windows Server 2003 \"R2\" ");
         else if( osvi.wProductType == VER_NT_WORKSTATION &&
            si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
         {
            printf( "Microsoft Windows XP Professional x64 Edition ");
         }
         else printf ("Microsoft Windows Server 2003, ");
      }

      if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
         printf ("Microsoft Windows XP ");

      if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
         printf ("Microsoft Windows 2000 ");

      if ( osvi.dwMajorVersion <= 4 )
         printf ("Microsoft Windows NT ");

      // Test for specific product on Windows NT 4.0 SP6 and later.
      if( bOsVersionInfoEx )
      {
         // Test for the workstation type.
         if ( osvi.wProductType == VER_NT_WORKSTATION &&
              si.wProcessorArchitecture!=PROCESSOR_ARCHITECTURE_AMD64)
         {
            if( osvi.dwMajorVersion == 4 )
               printf ( "Workstation 4.0 " );
            else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
               printf ( "Home Edition " );
            else printf ( "Professional " );
         }
            
         // Test for the server type.
         else if ( osvi.wProductType == VER_NT_SERVER ||
                   osvi.wProductType == VER_NT_DOMAIN_CONTROLLER )
         {
            if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==2)
            {
               if ( si.wProcessorArchitecture ==
                    PROCESSOR_ARCHITECTURE_IA64 )
               {
                   if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                      printf ( "Datacenter Edition "
                               "for Itanium-based Systems" );
                   else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                      printf ( "Enterprise Edition "
                               "for Itanium-based Systems" );
               }

               else if ( si.wProcessorArchitecture ==
                         PROCESSOR_ARCHITECTURE_AMD64 )
               {
                   if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                      printf ( "Datacenter x64 Edition " );
                   else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                      printf ( "Enterprise x64 Edition " );
                   else printf( "Standard x64 Edition " );
               }

               else
               {
                   if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                      printf ( "Datacenter Edition " );
                   else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                      printf ( "Enterprise Edition " );
                   else if ( osvi.wSuiteMask & VER_SUITE_BLADE )
                      printf ( "Web Edition " );
                   else printf ( "Standard Edition " );
               }
            }
            else if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==0)
            {
               if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                  printf ( "Datacenter Server " );
               else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                  printf ( "Advanced Server " );
               else printf ( "Server " );
            }
            else  // Windows NT 4.0
            {
               if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                  printf ("Server 4.0, Enterprise Edition " );
               else printf ( "Server 4.0 " );
            }
         }
      }
      // Test for specific product on Windows NT 4.0 SP5 and earlier
      else  
      {
         HKEY hKey;
         TCHAR szProductType[BUFSIZE];
         DWORD dwBufLen=BUFSIZE*sizeof(TCHAR);
         LONG lRet;

         lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
            TEXT("SYSTEM\\CurrentControlSet\\Control\\"
                 "ProductOptions"), 0, KEY_QUERY_VALUE, &hKey );
         if( lRet != ERROR_SUCCESS )
            return FALSE;

         lRet = RegQueryValueEx( hKey, TEXT("ProductType"),
            NULL, NULL, (LPBYTE) szProductType, &dwBufLen);
         RegCloseKey( hKey );

         if( (lRet != ERROR_SUCCESS) ||
             (dwBufLen > BUFSIZE*sizeof(TCHAR)) )
            return FALSE;

         if ( lstrcmpi( TEXT("WINNT"), szProductType) == 0 )
            printf( "Workstation " );
         if ( lstrcmpi( TEXT("LANMANNT"), szProductType) == 0 )
            printf( "Server " );
         if ( lstrcmpi( TEXT("SERVERNT"), szProductType) == 0 )
            printf( "Advanced Server " );
         printf( "%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion );
      }

      // Display service pack (if any) and build number.

      if( osvi.dwMajorVersion == 4 &&
          lstrcmpi( osvi.szCSDVersion, TEXT("Service Pack 6") ) == 0 )
      {
         HKEY hKey;
         LONG lRet;

         // Test for SP6 versus SP6a.
         lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
            TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\"
                 "Hotfix\\Q246009"), 0, KEY_QUERY_VALUE, &hKey );
         if( lRet == ERROR_SUCCESS )
            printf( "Service Pack 6a (Build %d)\n",
            osvi.dwBuildNumber & 0xFFFF );        
         else // Windows NT 4.0 prior to SP6a
         {
            _tprintf( TEXT("%s (Build %d)\n"),
               osvi.szCSDVersion,
               osvi.dwBuildNumber & 0xFFFF);
         }

         RegCloseKey( hKey );
      }
      else // not Windows NT 4.0
      {
         _tprintf( TEXT("%s (Build %d)\n"),
            osvi.szCSDVersion,
            osvi.dwBuildNumber & 0xFFFF);
      }

      break;

      // Test for the Windows Me/98/95.
      case VER_PLATFORM_WIN32_WINDOWS:

      if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
      {
          printf ("Microsoft Windows 95 ");
          if (osvi.szCSDVersion[1]=='C' || osvi.szCSDVersion[1]=='B')
             printf("OSR2 " );
      }

      if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
      {
          printf ("Microsoft Windows 98 ");
          if ( osvi.szCSDVersion[1]=='A' || osvi.szCSDVersion[1]=='B')
             printf("SE " );
      }

      if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
      {
          printf ("Microsoft Windows Millennium Edition\n");
      }
      break;

      case VER_PLATFORM_WIN32s:

      printf ("Microsoft Win32s\n");
      break;
   }
   return TRUE;
}