帮忙解决简单的两个问题~~~~~~~~~

countrynew 2002-03-20 07:00:29
1:是否有函数可以取得当前操作系统的安装目录?
2:我有什么办法可以在程序里判断用户用的是win98系统还是win2000系统?

小分送上~~~~
...全文
41 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
countrynew 2002-03-20
  • 打赏
  • 举报
回复
谢谢,谢谢
hnyyy 2002-03-20
  • 打赏
  • 举报
回复
Windows目录: Use "GetWindowsDirectory"
Windows下的system目录: Use "GetSystemDirectory"
temp目录: Use "GetTempPath"
当前目录: Use "GetCurrentDirectory"
操作系统:

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

BOOL DisplaySystemVersion()
{
OSVERSIONINFOEX osvi;
BOOL bOsVersionInfoEx;

// Try calling GetVersionEx using the OSVERSIONINFOEX structure,
// which is supported on Windows 2000.
//
// If that fails, try using the OSVERSIONINFO structure.

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

if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
{
// If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.

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

switch (osvi.dwPlatformId)
{
case VER_PLATFORM_WIN32_NT:

// Test for the product.

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

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

// Test for workstation versus server.

if( bOsVersionInfoEx )
{
if ( osvi.wProductType == VER_NT_WORKSTATION )
printf ( "Professional " );

if ( osvi.wProductType == VER_NT_SERVER )
printf ( "Server " );
}
else
{
HKEY hKey;
char szProductType[80];
DWORD dwBufLen;

RegOpenKeyEx( HKEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
0, KEY_QUERY_VALUE, &hKey );
RegQueryValueEx( hKey, "ProductType", NULL, NULL,
(LPBYTE) szProductType, &dwBufLen);
RegCloseKey( hKey );
if ( lstrcmpi( "WINNT", szProductType) == 0 )
printf( "Workstation " );
if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
printf( "Server " );
}

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

printf ("version %d.%d %s (Build %d)\n",
osvi.dwMajorVersion,
osvi.dwMinorVersion,
osvi.szCSDVersion,
osvi.dwBuildNumber & 0xFFFF);

break;

case VER_PLATFORM_WIN32_WINDOWS:

if ((osvi.dwMajorVersion > 4) ||
((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion > 0)))
{
printf ("Microsoft Windows 98 ");
}
else printf ("Microsoft Windows 95 ");

break;

case VER_PLATFORM_WIN32s:

printf ("Microsoft Win32s ");
break;
}
return TRUE;
}
strip 2002-03-20
  • 打赏
  • 举报
回复
如果你还想分清楚是95,98还是winme, 那就看这个帮助:
BOOL GetVersionEx(
LPOSVERSIONINFO lpVersionInfo // version information
);
strip 2002-03-20
  • 打赏
  • 举报
回复
1. UINT GetWindowsDirectory(
LPTSTR lpBuffer, // buffer for Windows directory
UINT uSize // size of directory buffer
);

2. DWORD GetVersion(VOID);
dwVersion = GetVersion();

// Get the Windows version.

dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));

// Get the build number.

if (dwVersion < 0x80000000) // Windows NT/2000, Whistler
dwBuild = (DWORD)(HIWORD(dwVersion));
else if (dwWindowsMajorVersion < 4) // Win32s
dwBuild = (DWORD)(HIWORD(dwVersion) & ~0x8000);
else

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧