MSDN上有详细介绍,做个标记:
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]
#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;
}