C/C++获得windows版本

4 篇文章 0 订阅
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

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



//使用控制台打开另外的程序,并把控制台隐藏掉
#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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值