`

C/C++获得windows版本

 
阅读更多
MSDN上有详细介绍,做个标记:
  #include <windows.h>
  #include <stdio.h>
  
  void main()
  {
      OSVERSIONINFO osvi;
      BOOL bIsWindowsXPorLater;
  
      ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
      osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  
      GetVersionEx(&osvi);
  
      bIsWindowsXPorLater = 
         ( (osvi.dwMajorVersion > 5) ||
         ( (osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion >= 1) ));
  
      if(bIsWindowsXPorLater)
          printf("The system meets the requirements.\n");
      else printf("The system does not meet the requirements.\n");
  }


Operating System Version (Windows)
Operating system         Version number
Windows 8                 6.2
Windows Server 2012         6.2
Windows 7                 6.1
Windows Server 2008 R2         6.1
Windows Server 2008         6.0
Windows Vista               6.0
Windows Server 2003 R2         5.2
Windows Server 2003         5.2
Windows XP 64-Bit Edition 5.2
Windows XP                 5.1
Windows 2000                 5.0

http://msdn.microsoft.com/ZH-CN/library/windows/desktop/ms724832(v=vs.85).aspx


//使用控制台打开另外的程序,并把控制台隐藏掉
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )

#include <Windows.h>
int main()
{
/*以下启动另一exe*/
SHELLEXECUTEINFO  ShExecInfo; 
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); 
ShExecInfo.fMask     = NULL; 
ShExecInfo.hwnd      = NULL; 
ShExecInfo.lpVerb    = NULL; 
ShExecInfo.lpFile    = ("E:\\Work_Project\\ParaExe\\ParaExe\\bin\\Debug\\ParaExe.exe");
ShExecInfo.lpParameters = NULL; 
ShExecInfo.lpDirectory     = NULL; 
ShExecInfo.nShow           = SW_MAXIMIZE;
ShExecInfo.hInstApp = NULL; 
ShellExecuteEx(&ShExecInfo); 

    /*以下检测插件安装情况*/

return 0;
}



// ChooseExeVersion.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>

#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )

typedef struct ExeOsPair_tag
{
	char osVersion[300];
	char exeVersion[300];
}ExeOsPair;

ExeOsPair g_exeOsPairs[100];
int g_exeOsPairsSize = 0;

int AddExeOsParis(const char *osVersion, const char* exeVersion)
{
	strcpy(g_exeOsPairs[g_exeOsPairsSize].exeVersion, exeVersion);
	strcpy(g_exeOsPairs[g_exeOsPairsSize].osVersion, osVersion);
	g_exeOsPairsSize++;
	return 0;
}

//int _tmain(int argc, _TCHAR* argv[])
int main()
{
	/*****************************************************/
	//add new exe and os pairs here
	/*
		Operating System Version (Windows): 
		http://msdn.microsoft.com/ZH-CN/library/windows/desktop/ms724832(v=vs.85).aspx

		Operating system			Version number
		Windows 8					6.2
		Windows Server 2012			6.2
		Windows 7					6.1
		Windows Server 2008 R2		6.1
		Windows Server 2008			6.0
		Windows Vista				6.0
		Windows Server 2003 R2		5.2
		Windows Server 2003			5.2
		Windows XP					5.1
		Windows 2000				5.0
	*/

	AddExeOsParis("6.1", "notepad.exe f:\\调用程序.txt");
	AddExeOsParis("6.0", "2.exe");
	AddExeOsParis("5.1", "3.exe");
	/*****************************************************/

	OSVERSIONINFO osvi;
	BOOL bIsWindowsXPorLater;

	ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

	if (GetVersionEx(&osvi) == 0)
	{
		printf("Error: %d\n", GetLastError());
		return -1;
	}

	char osVersion[100];
 	sprintf(osVersion, "%d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion);

#ifdef _DEBUG
	printf("Version is %d.%d (%d)\n", 
		osvi.dwMajorVersion,
		osvi.dwMinorVersion,
		osvi.dwBuildNumber);
#endif

	for (int i = 0; i< g_exeOsPairsSize; ++i)
	{
		if (strcmp(g_exeOsPairs[i].osVersion, osVersion) == 0)
		{
			WinExec(g_exeOsPairs[i].exeVersion, SW_SHOW);
			break;
		}
	}
	
	return 0;
}
分享到:
评论

相关推荐

    eclipse开发c/c++环境配置

    总的来说,配置Eclipse进行C/C++开发需要安装MinGW以获得编译环境,然后在Eclipse中设置环境变量、选择编译器和构建工具链,创建项目并配置相关构建设置。通过这样的配置,开发者可以在Eclipse的友好环境中进行高效...

    Borland C/C++ 3.1 完整版(BC3.1)

    1. **Borland C/C++**:Borland C/C++是Borland公司的旗舰级编程工具,它不仅提供了C语言的编译器,还包含了C++的编译支持。该套件以其高效、快速的编译速度和优秀的调试能力而闻名,同时还集成了代码编辑器、项目...

    C/C++高质量编程

    《C/C++高质量编程》由林锐博士撰写,是一份详尽且专业的指南,旨在提升C/C++程序员的编码质量,被广泛认为是C/C++程序员必读的经典之作。此书不仅涵盖了C/C++编程的基础知识,更深入探讨了如何编写高效、可维护的...

    Matlab安装MinGW-w64 C/C++ 编译器

    在使用Matlab进行C或C++编程时,有时需要编译和链接外部代码,这就需要一个合适的C/C++编译器。MinGW-w64是一个轻量级的、开源的Windows上的GCC(GNU Compiler Collection)移植版,它为32位和64位的Windows系统提供...

    C/C++:Windows编程—Hook IE浏览器实现URL拦截及更改 示例demo

    C/C++:Windows编程—Hook IE浏览器实现URL拦截及更改 示例demo https://blog.csdn.net/qq_29542611/article/details/103756071

    反编译工具(DLL 转c/c++ 工具)

    标题中的“反编译工具(DLL 转 c/c++ 工具)”是指一类能够将动态链接库(DLL)文件转换为C或C++源代码的软件工具。DLL是Windows操作系统中的一种共享库,它包含可由多个程序同时使用的函数和资源。这种转换过程在...

    C/C++ 定时器程序(含源码和demo)

    本资源提供了一个C/C++实现的定时器程序,包含源码和demo,支持在Windows和Linux上跨平台运行,这为我们提供了深入理解定时器机制和跨平台编程的一个实践案例。 首先,C++定时器的实现方式多种多样,常见的有以下几...

    c/c++完整视频教程(四)——–数据库(MySQL,Oracle)

    根据提供的文件信息,我们可以推断出本视频教程的第四部分主要关注的是如何在C/C++环境中操作和使用数据库,特别是MySQL和Oracle这两种广泛使用的数据库管理系统。下面将详细展开这一主题的相关知识点。 ### C/C++...

    C/C++与Python混编的详细文件

    1. **C/C++动态链接库**:.so文件是Linux系统下的动态链接库,类似于Windows中的.dll文件。它们包含可供其他程序调用的函数和数据。创建.so文件通常通过编译C/C++源代码,并使用`-shared`选项指定生成动态库来实现。...

    Windows Via C/C++,Fifth Edition .pdf

    《Windows Via C/C++, Fifth Edition》是一本由Jeffrey Richter和Christophe Nasarre编写的书籍,专注于通过C和C++语言探索Windows操作系统的核心功能和技术。本书详细讲解了如何在Windows平台上使用C/C++进行编程,...

    Mysql Connector C/C++ VS2013 编译(win32/win64)(附带示例代码)

    5. 同样,在“配置属性” -&gt; “C/C++” -&gt; “常规” -&gt; “附加包含目录”中,添加MySQL Connector/C++的头文件路径。 6. 完成以上设置后,你可以选择“生成” -&gt; “全部重新生成”来编译项目。如果编译成功,你将在...

    windows平台下C/C++代码覆盖率检查工具

    在Windows平台上进行C/C++开发时,代码覆盖率检查是一个重要的质量保证步骤,它能帮助开发者了解测试用例对源代码的覆盖程度。代码覆盖率通常包括行覆盖率、分支覆盖率等指标,能够评估测试的有效性,确保代码的健壮...

    VC、C/c++小词典编程助手

    这款小词典尤其针对使用Visual C++ (VC) 和C/C++语言的开发者,提供了丰富的参考资料,使得在编程过程中遇到的问题能够得到快速解决。 C/C++是两种广泛使用的编程语言,它们以其高效、灵活和强大的系统级编程能力而...

    c++获取windows文件版本信息

    本文将详细讨论如何使用C++编程语言,在Windows环境下通过两种方法获取文件版本信息:WinAPI函数和解析PE(Portable Executable)文件结构。 首先,我们来介绍WinAPI方法。Windows API提供了`GetFileVersionInfo`、...

    C/C++ 代码行统计工具SCCT-源码

    通过研究SCCT的源码,开发者不仅可以了解代码统计的具体实现,还能学习到C/C++编程、Windows应用程序开发、MFC框架应用、编译原理等多个方面的知识,这对于提升编程技能和软件工程实践能力非常有帮助。

    解决 Eclipse-CDT 搭建C/C++ 开发环境部分问题

    在使用Eclipse CDT进行C/C++开发时,可能会遇到一系列与环境配置和工具链相关的问题。本篇文章将深入探讨如何解决"Program "g++" not found in PATH"、"Lanuch failed no binaries"以及新建项目时找不到MinGW的问题...

    C/C++获取(毫秒/微秒/纳秒级)系统时间差方法大全

    在C/C++编程中,获取系统的毫秒、微秒或纳秒级时间差是常见的需求,特别是在性能测试、定时任务或者高精度计时场景中。本文将详细介绍四种常用的方法。 ### 方法一:利用 `SYSTEMTIME` `SYSTEMTIME` 结构体是...

    Windows Via C/C++ - Jeffrey Richter - Christophe Nasarre

    ### Windows Via C/C++ - Jeffrey Richter - Christophe Nasarre #### 书籍概述 《Windows Via C/C++》第五版是由Jeffrey Richter和Christophe Nasarre共同编著的一本经典著作,该书主要介绍了如何使用C/C++语言...

    C/C++程序设计学习与实验系统

    用户可以在这个平台上创建、编辑、编译和运行C或C++程序,同时获得即时的错误反馈,便于理解和修正问题。此外,系统的实验部分可能包括精心设计的编程任务,这些任务旨在锻炼用户的逻辑思维和问题解决能力。 【标签...

Global site tag (gtag.js) - Google Analytics