如何判断winodws版本(50)

  • 主题发起人 主题发起人 abcok
  • 开始时间 开始时间
A

abcok

Unregistered / Unconfirmed
GUEST, unregistred user!
1、一个delphi程序怎样判断它正在运行的windows版本?winxp or win72、winxp下日期2010/1/20被认为错误格式 要用2010-1-20,而win7下相反,如何解决?
 
2已经解决了,麻烦看看1是否有解呢?
 
function GetWindowsVersion: String; const cOsUnknown : Integer = -1; cOsWin95 : Integer = 0; cOsWin98 : Integer = 1; cOsWin98SE : Integer = 2; cOsWinME : Integer = 3; cOsWinNT : Integer = 4; cOsWin2000 : Integer = 5; cOsWinXP : Integer = 6; cOsWin7 : Integer = 7; var osVerInfo : TOSVersionInfo; majorVer, minorVer, VersionCode: Integer; begin osVerInfo.dwOSVersionInfoSize := SizeOf( TOSVersionInfo ); if ( GetVersionEx( osVerInfo ) ) then begin majorVer := osVerInfo.dwMajorVersion; minorVer := osVerInfo.dwMinorVersion; case ( osVerInfo.dwPlatformId ) of VER_PLATFORM_WIN32_NT : { Windows NT/2000/XP/7 } begin if ( majorVer <= 4 ) then VersionCode := cOsWinNT else if ( ( majorVer = 5 ) and ( minorVer= 0 ) ) then VersionCode := cOsWin2000 else if ( ( majorVer = 5) and ( minorVer = 1 ) ) then VersionCode := cOsWinXP else //我没装 Win7,这里的 5 和 2 是猜测的 //请安装了 Win7 的朋友测试一下究竟是多少 if ( ( majorVer = 5) and ( minorVer = 2 ) ) then VersionCode := cOsWin7 else VersionCode := cOsUnknown; end; VER_PLATFORM_WIN32_WINDOWS : { Windows 9x/ME } begin if ( ( majorVer = 4 ) and ( minorVer = 0 ) ) then VersionCode := cOsWin95 else if ( ( majorVer = 4 ) and ( minorVer = 10 ) ) then begin if ( osVerInfo.szCSDVersion[ 1 ] = 'A' ) then VersionCode := cOsWin98SE else VersionCode := cOsWin98; end else if ( ( majorVer = 4) and ( minorVer = 90 ) ) then VersionCode := cOsWinME else VersionCode := cOsUnknown; end; else VersionCode := cOsUnknown; end; { Final del Case} end else VersionCode := cOsUnknown; {Final del if} if ( VersionCode = cOsUnknown ) then Result := '(sistema no reconocido)' else if ( VersionCode = cOsWin95 ) then Result := 'Microsoft Windows 95' else if ( VersionCode = cOsWin98 ) then Result := 'Microsoft Windows 98' else if ( VersionCode = cOsWin98SE ) then Result := 'Microsoft Windows 98 Second Edition' else if ( VersionCode = cOsWinME ) then Result := 'Microsoft Windows Millennium Edition' else if ( VersionCode = cOsWinNT ) then Result := 'Microsoft Windows NT' else if ( VersionCode = cOsWin2000 ) then Result := 'Microsoft Windows 2000' else if ( VersionCode = cOsWinXP ) then Result := 'Microsoft Windows XP' else if ( VersionCode = cOsWin7 ) then Result := 'Microsoft Windows 7' else Result := 'Microsoft Windows'; Result:= Result + ' (Build '+IntToStr(osVerInfo.dwBuildNumber)+') ' + osVerInfo.szCSDVersion; end;
 
2、winxp下日期2010/1/20被认为错误格式 要用2010-1-20,而win7下相反,如何解决? --------------------在代码中用formatdatetime随便你用什么格式
 
感谢kaida!分给了!没想到判断一个版本竟然这么的复杂,呵呵
 
Win7的 if ( ( majorVer = 6) and ( minorVer = 1 ) ) then VersionCode := cOsWin7
 

Similar threads

回复
0
查看
804
不得闲
S
回复
0
查看
816
SUNSTONE的Delphi笔记
S
S
回复
0
查看
733
SUNSTONE的Delphi笔记
S
后退
顶部