C语言如何获取系统版本?就是说win XP,win7还是其他的什么
展开全部
调用API 读取注册表就OK了
#include <stdio.h>
#include <windows.h>
#include <tchar.h>
int main()
{
TCHAR buf[255];
int size;
HKEY hKey;
DWORD regType = REG_SZ;
LONG ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
0,
KEY_READ,
&hKey);
if(ret!=ERROR_SUCCESS)
{
_tprintf(TEXT("%s"), TEXT("无法打开\nHKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"));
return 1;
}
size = 254;
ret = RegQueryValueEx(hKey, "ProductName",0,®Type,
buf, &size);
if(ret!=ERROR_SUCCESS)
_tprintf(TEXT("%s"), TEXT("无法读取ProductName"));
else
_tprintf(TEXT("系统:%s\n"), buf);
size = 254;
ret = RegQueryValueEx(hKey, "CSDVersion",0,®Type,
buf, &size);
if(ret!=ERROR_SUCCESS)
_tprintf(TEXT("%s"), TEXT("无法读取CSDVersion"), TEXT("错误"));
else
_tprintf(TEXT("补丁包:%s\n"), buf);
size = 254;
ret = RegQueryValueEx(hKey, "CurrentVersion",0,®Type,
buf, &size);
if(ret!=ERROR_SUCCESS)
_tprintf(TEXT("%s"), TEXT("无法读取CurrentVersion"), TEXT("错误"));
else
_tprintf(TEXT("版本号:%s\n"), buf);
size = 254;
ret = RegQueryValueEx(hKey, "CurrentBuildNumber",0,®Type,
buf, &size);
if(ret!=ERROR_SUCCESS)
_tprintf(TEXT("%s"), TEXT("无法读取CurrentBuildNumber"), TEXT("错误"));
else
_tprintf(TEXT("子版本号:%s\n"), buf);
RegCloseKey(hKey);
return 0;
}
#include <stdio.h>
#include <windows.h>
#include <tchar.h>
int main()
{
TCHAR buf[255];
int size;
HKEY hKey;
DWORD regType = REG_SZ;
LONG ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
0,
KEY_READ,
&hKey);
if(ret!=ERROR_SUCCESS)
{
_tprintf(TEXT("%s"), TEXT("无法打开\nHKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"));
return 1;
}
size = 254;
ret = RegQueryValueEx(hKey, "ProductName",0,®Type,
buf, &size);
if(ret!=ERROR_SUCCESS)
_tprintf(TEXT("%s"), TEXT("无法读取ProductName"));
else
_tprintf(TEXT("系统:%s\n"), buf);
size = 254;
ret = RegQueryValueEx(hKey, "CSDVersion",0,®Type,
buf, &size);
if(ret!=ERROR_SUCCESS)
_tprintf(TEXT("%s"), TEXT("无法读取CSDVersion"), TEXT("错误"));
else
_tprintf(TEXT("补丁包:%s\n"), buf);
size = 254;
ret = RegQueryValueEx(hKey, "CurrentVersion",0,®Type,
buf, &size);
if(ret!=ERROR_SUCCESS)
_tprintf(TEXT("%s"), TEXT("无法读取CurrentVersion"), TEXT("错误"));
else
_tprintf(TEXT("版本号:%s\n"), buf);
size = 254;
ret = RegQueryValueEx(hKey, "CurrentBuildNumber",0,®Type,
buf, &size);
if(ret!=ERROR_SUCCESS)
_tprintf(TEXT("%s"), TEXT("无法读取CurrentBuildNumber"), TEXT("错误"));
else
_tprintf(TEXT("子版本号:%s\n"), buf);
RegCloseKey(hKey);
return 0;
}
追问
不能编译……哪里错了吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
struct utsname {
char sysname[]; /* Operating system name (e.g., "Linux") */
char nodename[]; /* Name within "some implementation-defined
network" */
char release[]; /* OS release (e.g., "2.6.28") */
char version[]; /* OS version */
char machine[]; /* Hardware identifier */
#ifdef _GNU_SOURCE
char domainname[]; /* NIS or YP domain name */
#endif
};
char sysname[]; /* Operating system name (e.g., "Linux") */
char nodename[]; /* Name within "some implementation-defined
network" */
char release[]; /* OS release (e.g., "2.6.28") */
char version[]; /* OS version */
char machine[]; /* Hardware identifier */
#ifdef _GNU_SOURCE
char domainname[]; /* NIS or YP domain name */
#endif
};
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-03-01
展开全部
很简单的!运行 systeminfo命令
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |